StrategyContext 在设定 ktypes 时进行从小到大的排序,以便后续能够按顺序调用 onBar

This commit is contained in:
fasiondog 2024-05-07 01:49:38 +08:00
parent 53ee558b6e
commit 12ce26e07d
3 changed files with 39 additions and 1 deletions

View File

@ -21,6 +21,12 @@ void StrategyContext::setKTypeList(const vector<KQuery::KType>& ktypeList) {
to_upper(ktype);
return ktype;
});
// 对 ktype 按时间长度进行升序排序
std::sort(m_ktypeList.begin(), m_ktypeList.end(),
[](const KQuery::KType& a, const KQuery::KType& b) {
return KQuery::getKTypeInMin(a) < KQuery::getKTypeInMin(b);
});
}
bool StrategyContext::isAll() const {

View File

@ -46,12 +46,13 @@ public:
void setKTypeList(const vector<KQuery::KType>& ktypeList);
/** 该返回的 ktype 列表,已经按从小到大进行排序 */
const vector<KQuery::KType>& getKTypeList() const {
return m_ktypeList;
}
private:
Datetime m_startDatetime;
Datetime m_startDatetime{19901219};
vector<string> m_stockCodeList;
vector<KQuery::KType> m_ktypeList;
};

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 hikyuu.org
*
* Created on: 2024-05-07
* Author: fasiondog
*/
#include "../test_config.h"
#include "hikyuu/StrategyContext.h"
/**
* @defgroup test_hikyuu_StrategyContext test_hikyuu_StrategyContext
* @ingroup test_hikyuu_base_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_StrategyContext") {
StrategyContext sc;
sc.setKTypeList(
{KQuery::MONTH, KQuery::MIN5, KQuery::DAY, KQuery::MIN, KQuery::WEEK, KQuery::MIN60});
vector<KQuery::KType> expect{KQuery::MIN, KQuery::MIN5, KQuery::MIN60,
KQuery::DAY, KQuery::WEEK, KQuery::MONTH};
const auto ktypes = sc.getKTypeList();
for (size_t i = 0, len = ktypes.size(); i < len; i++) {
CHECK_EQ(ktypes[i], expect[i]);
}
}
/** @} */