mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 10:59:43 +08:00
StrategyContext 在设定 ktypes 时进行从小到大的排序,以便后续能够按顺序调用 onBar
This commit is contained in:
parent
53ee558b6e
commit
12ce26e07d
@ -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 {
|
||||
|
@ -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;
|
||||
};
|
||||
|
31
hikyuu_cpp/unit_test/hikyuu/hikyuu/test_StrategyContext.cpp
Normal file
31
hikyuu_cpp/unit_test/hikyuu/hikyuu/test_StrategyContext.cpp
Normal 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]);
|
||||
}
|
||||
}
|
||||
|
||||
/** @} */
|
Loading…
Reference in New Issue
Block a user