mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-02 03:48:19 +08:00
fixed 日期型KQuery比较
This commit is contained in:
parent
f320be9161
commit
ada77b9f05
@ -176,14 +176,24 @@ HKU_API std::ostream& operator<<(std::ostream& os, const KQuery& query) {
|
||||
|
||||
bool HKU_API operator!=(const KQuery& q1, const KQuery& q2) {
|
||||
// cppcheck-suppress [mismatchingContainerExpression]
|
||||
return q1.start() != q2.start() || q1.end() != q2.end() || q1.queryType() != q2.queryType() ||
|
||||
q1.kType() != q2.kType() || q1.recoverType() != q2.recoverType();
|
||||
HKU_IF_RETURN(q1.queryType() != q2.queryType(), true);
|
||||
if (q1.queryType() == KQuery::DATE) {
|
||||
return q1.kType() != q2.kType() || q1.recoverType() != q2.recoverType() ||
|
||||
q1.startDatetime() != q2.startDatetime() || q1.endDatetime() != q2.endDatetime();
|
||||
}
|
||||
return q1.kType() != q2.kType() || q1.recoverType() != q2.recoverType() ||
|
||||
q1.start() != q2.start() || q1.end() != q2.end();
|
||||
}
|
||||
|
||||
bool HKU_API operator==(const KQuery& q1, const KQuery& q2) {
|
||||
// cppcheck-suppress [mismatchingContainerExpression]
|
||||
return q1.start() == q2.start() && q1.end() == q2.end() && q1.queryType() == q2.queryType() &&
|
||||
q1.kType() == q2.kType() && q1.recoverType() == q2.recoverType();
|
||||
HKU_IF_RETURN(q1.queryType() != q2.queryType(), false);
|
||||
if (q1.queryType() == KQuery::DATE) {
|
||||
return q1.kType() == q2.kType() && q1.recoverType() == q2.recoverType() &&
|
||||
q1.startDatetime() == q2.startDatetime() && q1.endDatetime() == q2.endDatetime();
|
||||
}
|
||||
return q1.kType() == q2.kType() && q1.recoverType() == q2.recoverType() &&
|
||||
q1.start() == q2.start() && q1.end() == q2.end();
|
||||
}
|
||||
|
||||
} // namespace hku
|
||||
|
73
hikyuu_cpp/unit_test/hikyuu/hikyuu/test_KQuery.cpp
Normal file
73
hikyuu_cpp/unit_test/hikyuu/hikyuu/test_KQuery.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2019~2023, hikyuu.org
|
||||
*
|
||||
* History:
|
||||
* 1. 20240916 added by fasiondog
|
||||
*/
|
||||
|
||||
#include "../test_config.h"
|
||||
#include <hikyuu/KQuery.h>
|
||||
|
||||
using namespace hku;
|
||||
|
||||
/**
|
||||
* @defgroup test_hikyuu_KQuery test_hikyuu_KQuery
|
||||
* @ingroup test_hikyuu_base_suite
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @par 检测点 */
|
||||
TEST_CASE("test_KQuery") {
|
||||
KQuery q1 = KQueryByIndex(-1);
|
||||
CHECK_EQ(q1.start(), -1);
|
||||
CHECK_UNARY(q1.end() == Null<int64_t>());
|
||||
CHECK_UNARY(q1.startDatetime() == Null<Datetime>());
|
||||
CHECK_UNARY(q1.endDatetime() == Null<Datetime>());
|
||||
|
||||
q1 = KQueryByDate(Datetime(20010101), Datetime(20010110));
|
||||
CHECK_UNARY(q1.start() == Null<int64_t>());
|
||||
CHECK_UNARY(q1.end() == Null<int64_t>());
|
||||
CHECK_EQ(q1.startDatetime(), Datetime(20010101));
|
||||
CHECK_EQ(q1.endDatetime(), Datetime(20010110));
|
||||
}
|
||||
|
||||
/** @par 检测点 */
|
||||
TEST_CASE("test_KQuery_equal") {
|
||||
KQuery q1 = KQueryByIndex(-1);
|
||||
KQuery q2 = KQueryByIndex(-1);
|
||||
CHECK_EQ(q1, q2);
|
||||
|
||||
q1 = KQueryByIndex(-1);
|
||||
q2 = KQueryByIndex(2);
|
||||
CHECK_NE(q1, q2);
|
||||
|
||||
q1 = KQueryByIndex(2);
|
||||
q2 = KQueryByIndex(2, 3);
|
||||
CHECK_NE(q1, q2);
|
||||
|
||||
q1 = KQueryByIndex(2);
|
||||
q2 = KQueryByIndex(2);
|
||||
CHECK_EQ(q1, q2);
|
||||
|
||||
q1 = KQueryByIndex(2, 10);
|
||||
q2 = KQueryByIndex(2, 10);
|
||||
CHECK_EQ(q1, q2);
|
||||
|
||||
q1 = KQueryByDate(Datetime(20010101));
|
||||
q2 = KQueryByIndex(2, 10);
|
||||
CHECK_NE(q1, q2);
|
||||
|
||||
q1 = KQueryByDate(Datetime(20010101));
|
||||
q2 = KQueryByDate(Datetime(20010101));
|
||||
CHECK_EQ(q1, q2);
|
||||
|
||||
q1 = KQueryByDate(Datetime(20010101));
|
||||
q2 = KQueryByDate(Datetime(20010101), Datetime(20010102));
|
||||
CHECK_NE(q1, q2);
|
||||
|
||||
q1 = KQueryByDate(Datetime(20010101), Datetime(20010110));
|
||||
q2 = KQueryByDate(Datetime(20010101), Datetime(20010110));
|
||||
CHECK_EQ(q1, q2);
|
||||
}
|
||||
|
||||
/** @} */
|
Loading…
Reference in New Issue
Block a user