switch BOOST.TEST to doctest

This commit is contained in:
fasiondog 2019-12-30 00:19:35 +08:00
parent b8bd278273
commit 1868afd766
161 changed files with 12652 additions and 13810 deletions

View File

@ -0,0 +1,407 @@
/*
* test_datetime.cpp
*
* Created on: 2012-8-25
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <hikyuu/datetime/Datetime.h>
#include <hikyuu/utilities/Null.h>
using namespace hku;
/**
* @defgroup test_hikyuu_Datetime test_hikyuu_Datetime
* @ingroup test_hikyuu_datetime_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_Datetime") {
Datetime null_datetime = Null<Datetime>();
/** @arg 默认无参构造函数返回Null<Datetime>() */
Datetime d;
CHECK(d == Null<Datetime>());
CHECK(Null<Datetime>() == d);
d = Datetime(201208062359);
CHECK(d < Null<Datetime>());
/** @arg 从Null<unsigned long long>()构造 */
d = Datetime(Null<unsigned long long>());
CHECK(d == Null<Datetime>());
/** @arg 从bd::date 隐式构造 */
d = Datetime(200101010110);
d = Datetime(d.date());
CHECK(Datetime(200101010000) == d);
/** @arg 非法年份 */
CHECK_THROWS_AS(Datetime(99999, 1, 1), std::out_of_range);
CHECK_THROWS_AS(Datetime(000001010000L), std::out_of_range);
/** @arg 非法月份 */
CHECK_THROWS_AS(Datetime(2010, 13, 1), std::out_of_range);
CHECK_THROWS_AS(Datetime(2010, 0, 1), std::out_of_range);
CHECK_THROWS_AS(Datetime(201013010000L), std::out_of_range);
CHECK_THROWS_AS(Datetime(201000010000L), std::out_of_range);
/** @arg 非法日期 */
CHECK_THROWS_AS(Datetime(2010, 1, 0), std::out_of_range);
CHECK_THROWS_AS(Datetime(2010, 1, 32), std::out_of_range);
CHECK_THROWS_AS(Datetime(201001000000L), std::out_of_range);
CHECK_THROWS_AS(Datetime(201001320000L), std::out_of_range);
/** @arg 非法小时 */
CHECK_THROWS_AS(Datetime(201001012400L), std::out_of_range);
CHECK_THROWS_AS(Datetime(201001012500L), std::out_of_range);
/** @arg 非法分钟 */
CHECK_THROWS_AS(Datetime(201001010060L), std::out_of_range);
CHECK_THROWS_AS(Datetime(201001010061L), std::out_of_range);
/** @arg 属性读取 */
d = Datetime(2012, 8, 6, 23, 59, 2, 13, 15);
CHECK(2012 == d.year());
CHECK(8 == d.month());
CHECK(6 == d.day());
CHECK(23 == d.hour());
CHECK(59 == d.minute());
CHECK(2 == d.second());
CHECK(13 == d.millisecond());
CHECK(15 == d.microsecond());
/** @arg Null<Datetime> 获取熟悉 */
d = Datetime();
CHECK_THROWS_AS(d.year(), std::logic_error);
CHECK_THROWS_AS(d.month(), std::logic_error);
CHECK_THROWS_AS(d.day(), std::logic_error);
CHECK_THROWS_AS(d.hour(), std::logic_error);
CHECK_THROWS_AS(d.minute(), std::logic_error);
CHECK_THROWS_AS(d.second(), std::logic_error);
CHECK_THROWS_AS(d.millisecond(), std::logic_error);
CHECK_THROWS_AS(d.microsecond(), std::logic_error);
/** @arg 正常日期转化为unsigned long long */
d = Datetime(201208062359);
unsigned long long x = d.number();
CHECK(x == 201208062359);
long long y = x;
Datetime m(y);
CHECK(m == d);
/** @arg Null<Datetime>()转化为number */
x = Null<unsigned long long>();
d = Null<Datetime>();
CHECK(x == d.number());
/** @arg 测试 str */
d = Datetime("2001-Jan-01 06:30:00");
CHECK("2001-01-01 06:30:00" == d.str());
d = Datetime("2001-Jan-01 06:30:00.001");
CHECK("2001-01-01 06:30:00.001000" == d.str());
/** @arg 测试 dayOfWeek*/
CHECK(Datetime(201801010000L).dayOfWeek() == 1);
CHECK(Datetime(201801060000L).dayOfWeek() == 6);
CHECK(Datetime(201801070000L).dayOfWeek() == 0);
/** @arg 测试 dayOfYear*/
CHECK(Datetime(201801010000L).dayOfYear() == 1);
CHECK(Datetime(201812310000L).dayOfYear() == 365);
/** @arg 测试 dateOfWeek */
CHECK(null_datetime.dateOfWeek(-1) == null_datetime);
CHECK(null_datetime.dateOfWeek(0) == null_datetime);
CHECK(null_datetime.dateOfWeek(4) == null_datetime);
CHECK(null_datetime.dateOfWeek(6) == null_datetime);
CHECK(null_datetime.dateOfWeek(7) == null_datetime);
CHECK(Datetime(201901010000).dateOfWeek(-1) == Datetime(201812300000));
CHECK(Datetime(201901010000).dateOfWeek(0) == Datetime(201812300000));
CHECK(Datetime(201901010000).dateOfWeek(1) == Datetime(201812310000));
CHECK(Datetime(201901010000).dateOfWeek(2) == Datetime(201901010000));
CHECK(Datetime(201901010000).dateOfWeek(3) == Datetime(201901020000));
CHECK(Datetime(201901010000).dateOfWeek(4) == Datetime(201901030000));
CHECK(Datetime(201901010000).dateOfWeek(5) == Datetime(201901040000));
CHECK(Datetime(201901010000).dateOfWeek(6) == Datetime(201901050000));
CHECK(Datetime(201901010000).dateOfWeek(7) == Datetime(201901050000));
/** @arg 测试 startOfDay */
CHECK(null_datetime.startOfDay() == null_datetime);
CHECK(Datetime::min().startOfDay() == Datetime::min());
CHECK(Datetime::max().startOfDay() == Datetime::max());
CHECK(Datetime(201812310110).startOfDay() == Datetime(201812310000));
/** @arg 测试 endOfDay */
CHECK(null_datetime.endOfDay() == null_datetime);
CHECK(Datetime::min().endOfDay() == Datetime(1400, 1, 1, 23, 59, 59));
CHECK(Datetime::max().endOfDay() == Datetime::max());
CHECK(Datetime(201812310110).endOfDay() == Datetime(2018, 12, 31, 23, 59, 59));
/** @arg 测试 startOfWeek */
CHECK(null_datetime.startOfWeek() == null_datetime);
CHECK(Datetime::min().startOfWeek() == Datetime::min());
CHECK(Datetime::max().startOfWeek() == Datetime(9999, 12, 27));
CHECK(Datetime(201812310000).startOfWeek() == Datetime(201812310000));
CHECK(Datetime(201901050000).startOfWeek() == Datetime(201812310000));
CHECK(Datetime(201901060000).startOfWeek() == Datetime(201812310000));
CHECK(Datetime(201901090000).startOfWeek() == Datetime(201901070000));
/** @arg 测试 endOfWeek */
CHECK(null_datetime.endOfWeek() == null_datetime);
CHECK(Datetime::min().endOfWeek() == Datetime(1400, 1, 5));
CHECK(Datetime::max().endOfWeek() == Datetime::max());
CHECK(Datetime(201812310000).endOfWeek() == Datetime(201901060000));
CHECK(Datetime(201901050000).endOfWeek() == Datetime(201901060000));
CHECK(Datetime(201901060000).endOfWeek() == Datetime(201901060000));
CHECK(Datetime(201901090000).endOfWeek() == Datetime(201901130000));
/** @arg 测试 startOfMonth */
CHECK(null_datetime.startOfMonth() == null_datetime);
CHECK(Datetime::min().startOfMonth() == Datetime::min());
CHECK(Datetime::max().startOfMonth() == Datetime(9999, 12, 1));
CHECK(Datetime(201901050000).startOfMonth() == Datetime(201901010000));
CHECK(Datetime(201902050000).startOfMonth() == Datetime(201902010000));
CHECK(Datetime(201902010000).startOfMonth() == Datetime(201902010000));
CHECK(Datetime(201903030000).startOfMonth() == Datetime(201903010000));
CHECK(Datetime(201904030000).startOfMonth() == Datetime(201904010000));
CHECK(Datetime(201912030000).startOfMonth() == Datetime(201912010000));
/** @arg 测试 endOfMonth*/
CHECK(null_datetime.endOfMonth() == null_datetime);
CHECK(Datetime::max().endOfMonth() == Datetime::max());
CHECK(Datetime::min().endOfMonth() == Datetime(1400, 1, 31));
CHECK(Datetime(201801010000L).endOfMonth() == Datetime(201801310000L));
CHECK(Datetime(201802010000L).endOfMonth() == Datetime(201802280000L));
CHECK(Datetime(201803010000L).endOfMonth() == Datetime(201803310000L));
CHECK(Datetime(201804010000L).endOfMonth() == Datetime(201804300000L));
CHECK(Datetime(201805010000L).endOfMonth() == Datetime(201805310000L));
CHECK(Datetime(201806010000L).endOfMonth() == Datetime(201806300000L));
CHECK(Datetime(201807010000L).endOfMonth() == Datetime(201807310000L));
CHECK(Datetime(201808010000L).endOfMonth() == Datetime(201808310000L));
CHECK(Datetime(201809010000L).endOfMonth() == Datetime(201809300000L));
CHECK(Datetime(201810010000L).endOfMonth() == Datetime(201810310000L));
CHECK(Datetime(201811010000L).endOfMonth() == Datetime(201811300000L));
CHECK(Datetime(201812010000L).endOfMonth() == Datetime(201812310000L));
/** @arg 测试 startOfQuarter */
CHECK(null_datetime.startOfQuarter() == null_datetime);
CHECK(Datetime::min().startOfQuarter() == Datetime::min());
CHECK(Datetime::max().startOfQuarter() == Datetime(9999, 10, 1));
CHECK(Datetime(201902050000).startOfQuarter() == Datetime(201901010000));
CHECK(Datetime(201901010000).startOfQuarter() == Datetime(201901010000));
CHECK(Datetime(201903310000).startOfQuarter() == Datetime(201901010000));
CHECK(Datetime(201904010000).startOfQuarter() == Datetime(201904010000));
CHECK(Datetime(201905010000).startOfQuarter() == Datetime(201904010000));
CHECK(Datetime(201906300000).startOfQuarter() == Datetime(201904010000));
CHECK(Datetime(201907010000).startOfQuarter() == Datetime(201907010000));
CHECK(Datetime(201907060000).startOfQuarter() == Datetime(201907010000));
CHECK(Datetime(201909300000).startOfQuarter() == Datetime(201907010000));
CHECK(Datetime(201910010000).startOfQuarter() == Datetime(201910010000));
CHECK(Datetime(201911010000).startOfQuarter() == Datetime(201910010000));
CHECK(Datetime(201912310000).startOfQuarter() == Datetime(201910010000));
/** @arg 测试 endOfQuarter */
CHECK(null_datetime.endOfQuarter() == null_datetime);
CHECK(Datetime::min().endOfQuarter() == Datetime(1400, 3, 31));
CHECK(Datetime::max().endOfQuarter() == Datetime::max());
CHECK(Datetime(201902050000).endOfQuarter() == Datetime(201903310000));
CHECK(Datetime(201901010000).endOfQuarter() == Datetime(201903310000));
CHECK(Datetime(201903310000).endOfQuarter() == Datetime(201903310000));
CHECK(Datetime(201904010000).endOfQuarter() == Datetime(201906300000));
CHECK(Datetime(201905010000).endOfQuarter() == Datetime(201906300000));
CHECK(Datetime(201906300000).endOfQuarter() == Datetime(201906300000));
CHECK(Datetime(201907010000).endOfQuarter() == Datetime(201909300000));
CHECK(Datetime(201907060000).endOfQuarter() == Datetime(201909300000));
CHECK(Datetime(201909300000).endOfQuarter() == Datetime(201909300000));
CHECK(Datetime(201910010000).endOfQuarter() == Datetime(201912310000));
CHECK(Datetime(201911010000).endOfQuarter() == Datetime(201912310000));
CHECK(Datetime(201912310000).endOfQuarter() == Datetime(201912310000));
/** @arg 测试 startOfHalfyear */
CHECK(null_datetime.startOfHalfyear() == null_datetime);
CHECK(Datetime::min().startOfHalfyear() == Datetime::min());
CHECK(Datetime::max().startOfHalfyear() == Datetime(9999, 7, 1));
CHECK(Datetime(201812310000).startOfHalfyear() == Datetime(201807010000));
CHECK(Datetime(201901010000).startOfHalfyear() == Datetime(201901010000));
CHECK(Datetime(201901020000).startOfHalfyear() == Datetime(201901010000));
CHECK(Datetime(201906050000).startOfHalfyear() == Datetime(201901010000));
CHECK(Datetime(201906300000).startOfHalfyear() == Datetime(201901010000));
CHECK(Datetime(201907010000).startOfHalfyear() == Datetime(201907010000));
CHECK(Datetime(201907100000).startOfHalfyear() == Datetime(201907010000));
CHECK(Datetime(201912010000).startOfHalfyear() == Datetime(201907010000));
CHECK(Datetime(201912310000).startOfHalfyear() == Datetime(201907010000));
/** @arg 测试 endOfHalfyear */
CHECK(null_datetime.endOfHalfyear() == null_datetime);
CHECK(Datetime::min().endOfHalfyear() == Datetime(1400, 6, 30));
CHECK(Datetime::max().endOfHalfyear() == Datetime::max());
CHECK(Datetime(201812310000).endOfHalfyear() == Datetime(201812310000));
CHECK(Datetime(201901010000).endOfHalfyear() == Datetime(201906300000));
CHECK(Datetime(201901020000).endOfHalfyear() == Datetime(201906300000));
CHECK(Datetime(201906050000).endOfHalfyear() == Datetime(201906300000));
CHECK(Datetime(201906300000).endOfHalfyear() == Datetime(201906300000));
CHECK(Datetime(201907010000).endOfHalfyear() == Datetime(201912310000));
CHECK(Datetime(201907100000).endOfHalfyear() == Datetime(201912310000));
CHECK(Datetime(201912010000).endOfHalfyear() == Datetime(201912310000));
CHECK(Datetime(201912310000).endOfHalfyear() == Datetime(201912310000));
/** @arg 测试 startOfYear */
CHECK(null_datetime.startOfYear() == null_datetime);
CHECK(Datetime::min().startOfYear() == Datetime::min());
CHECK(Datetime::max().startOfYear() == Datetime(9999, 1, 1));
CHECK(Datetime(201901050000).startOfYear() == Datetime(201901010000));
CHECK(Datetime(201911050000).startOfYear() == Datetime(201901010000));
/** @arg 测试 endOfYear */
CHECK(null_datetime.endOfYear() == null_datetime);
CHECK(Datetime::min().endOfYear() == Datetime(1400, 12, 31));
CHECK(Datetime::max().endOfYear() == Datetime::max());
CHECK(Datetime(201902050000).endOfYear() == Datetime(201912310000));
CHECK(Datetime(201912310000).endOfYear() == Datetime(201912310000));
/** @arg 测试 nextDay */
CHECK(null_datetime.nextDay() == null_datetime);
CHECK(Datetime::max().nextDay() == Datetime::max());
CHECK(Datetime(201802060000L).nextDay() == Datetime(201802070000L));
CHECK(Datetime(201802280000L).nextDay() == Datetime(201803010000L));
CHECK(Datetime(201602280000L).nextDay() == Datetime(201602290000L));
/** @arg 测试 nextWeek */
CHECK(null_datetime.nextWeek() == null_datetime);
CHECK(Datetime::max().nextWeek() == Datetime::max());
CHECK(Datetime(201812300000).nextWeek() == Datetime(201812310000));
CHECK(Datetime(201812310000).nextWeek() == Datetime(201901070000));
CHECK(Datetime(201901010000).nextWeek() == Datetime(201901070000));
CHECK(Datetime(201901020000).nextWeek() == Datetime(201901070000));
CHECK(Datetime(201901030000).nextWeek() == Datetime(201901070000));
CHECK(Datetime(201901040000).nextWeek() == Datetime(201901070000));
CHECK(Datetime(201901050000).nextWeek() == Datetime(201901070000));
CHECK(Datetime(201901060000).nextWeek() == Datetime(201901070000));
CHECK(Datetime(201901070000).nextWeek() == Datetime(201901140000));
/** @arg 测试 nextMonth */
CHECK(null_datetime.nextMonth() == null_datetime);
CHECK(Datetime::max().nextMonth() == Datetime::max());
CHECK(Datetime(201812310000).nextMonth() == Datetime(201901010000));
CHECK(Datetime(201901010000).nextMonth() == Datetime(201902010000));
CHECK(Datetime(201901310000).nextMonth() == Datetime(201902010000));
/** @arg 测试 nextQuarter */
CHECK(null_datetime.nextQuarter() == null_datetime);
CHECK(Datetime::max().nextQuarter() == Datetime::max());
CHECK(Datetime(201901010000).nextQuarter() == Datetime(201904010000));
CHECK(Datetime(201902010000).nextQuarter() == Datetime(201904010000));
CHECK(Datetime(201903310000).nextQuarter() == Datetime(201904010000));
CHECK(Datetime(201904010000).nextQuarter() == Datetime(201907010000));
CHECK(Datetime(201905010000).nextQuarter() == Datetime(201907010000));
CHECK(Datetime(201906300000).nextQuarter() == Datetime(201907010000));
CHECK(Datetime(201907010000).nextQuarter() == Datetime(201910010000));
CHECK(Datetime(201907020000).nextQuarter() == Datetime(201910010000));
CHECK(Datetime(201908010000).nextQuarter() == Datetime(201910010000));
CHECK(Datetime(201909300000).nextQuarter() == Datetime(201910010000));
CHECK(Datetime(201910010000).nextQuarter() == Datetime(202001010000));
CHECK(Datetime(201911010000).nextQuarter() == Datetime(202001010000));
CHECK(Datetime(201912310000).nextQuarter() == Datetime(202001010000));
/** @arg 测试 nextHalfyear */
CHECK(null_datetime.nextHalfyear() == null_datetime);
CHECK(Datetime::max().nextHalfyear() == Datetime::max());
CHECK(Datetime(201812310000).nextHalfyear() == Datetime(201901010000));
CHECK(Datetime(201901010000).nextHalfyear() == Datetime(201907010000));
CHECK(Datetime(201905050000).nextHalfyear() == Datetime(201907010000));
CHECK(Datetime(201906300000).nextHalfyear() == Datetime(201907010000));
CHECK(Datetime(201907010000).nextHalfyear() == Datetime(202001010000));
CHECK(Datetime(201910110000).nextHalfyear() == Datetime(202001010000));
CHECK(Datetime(201912310000).nextHalfyear() == Datetime(202001010000));
/** @arg 测试 nextYear */
CHECK(null_datetime.nextYear() == null_datetime);
CHECK(Datetime::max().nextYear() == Datetime::max());
CHECK(Datetime(201812310000).nextYear() == Datetime(201901010000));
CHECK(Datetime(201901010000).nextYear() == Datetime(202001010000));
CHECK(Datetime(201901020000).nextYear() == Datetime(202001010000));
CHECK(Datetime(201907310000).nextYear() == Datetime(202001010000));
CHECK(Datetime(201912310000).nextYear() == Datetime(202001010000));
/** @arg 测试 preDay */
CHECK(null_datetime.preDay() == null_datetime);
CHECK(Datetime::min().preDay() == Datetime::min());
CHECK(Datetime(201812310000).preDay() == Datetime(201812300000));
CHECK(Datetime(201901010000).preDay() == Datetime(201812310000));
CHECK(Datetime(201901020000).preDay() == Datetime(201901010000));
/** @arg 测试 preWeek */
CHECK(null_datetime.preWeek() == null_datetime);
CHECK(Datetime::min().preWeek() == Datetime::min());
CHECK(Datetime(201812310000).preWeek() == Datetime(201812240000));
CHECK(Datetime(201901010000).preWeek() == Datetime(201812240000));
CHECK(Datetime(201901020000).preWeek() == Datetime(201812240000));
CHECK(Datetime(201901030000).preWeek() == Datetime(201812240000));
CHECK(Datetime(201901040000).preWeek() == Datetime(201812240000));
CHECK(Datetime(201901050000).preWeek() == Datetime(201812240000));
CHECK(Datetime(201901060000).preWeek() == Datetime(201812240000));
CHECK(Datetime(201901070000).preWeek() == Datetime(201812310000));
/** @arg 测试 preMonth */
CHECK(null_datetime.preMonth() == null_datetime);
CHECK(Datetime::min().preMonth() == Datetime::min());
CHECK(Datetime(201602290000).preMonth() == Datetime(201601010000));
CHECK(Datetime(201901010000).preMonth() == Datetime(201812010000));
CHECK(Datetime(201901020000).preMonth() == Datetime(201812010000));
CHECK(Datetime(201901310000).preMonth() == Datetime(201812010000));
CHECK(Datetime(201902010000).preMonth() == Datetime(201901010000));
CHECK(Datetime(201902280000).preMonth() == Datetime(201901010000));
CHECK(Datetime(201903010000).preMonth() == Datetime(201902010000));
CHECK(Datetime(201903310000).preMonth() == Datetime(201902010000));
CHECK(Datetime(201904010000).preMonth() == Datetime(201903010000));
CHECK(Datetime(201904300000).preMonth() == Datetime(201903010000));
CHECK(Datetime(201905300000).preMonth() == Datetime(201904010000));
CHECK(Datetime(201912310000).preMonth() == Datetime(201911010000));
CHECK(Datetime(201912300000).preMonth() == Datetime(201911010000));
/** @arg 测试 preQuarter */
CHECK(null_datetime.preQuarter() == null_datetime);
CHECK(Datetime::min().preQuarter() == Datetime::min());
CHECK(Datetime(201901010000).preQuarter() == Datetime(201810010000));
CHECK(Datetime(201903310000).preQuarter() == Datetime(201810010000));
CHECK(Datetime(201904010000).preQuarter() == Datetime(201901010000));
CHECK(Datetime(201906300000).preQuarter() == Datetime(201901010000));
CHECK(Datetime(201907010000).preQuarter() == Datetime(201904010000));
CHECK(Datetime(201909300000).preQuarter() == Datetime(201904010000));
CHECK(Datetime(201910010000).preQuarter() == Datetime(201907010000));
CHECK(Datetime(201912310000).preQuarter() == Datetime(201907010000));
/** @arg 测试 preHalfyear() */
CHECK(null_datetime.preHalfyear() == null_datetime);
CHECK(Datetime::min().preHalfyear() == Datetime::min());
CHECK(Datetime(201901010000).preHalfyear() == Datetime(201807010000));
CHECK(Datetime(201906300000).preHalfyear() == Datetime(201807010000));
CHECK(Datetime(201907010000).preHalfyear() == Datetime(201901010000));
CHECK(Datetime(201912310000).preHalfyear() == Datetime(201901010000));
CHECK(Datetime(202001010000).preHalfyear() == Datetime(201907010000));
/** @arg 测试 preYear */
CHECK(null_datetime.preYear() == null_datetime);
CHECK(Datetime::min().preYear() == Datetime::min());
CHECK(Datetime(201901010000).preYear() == Datetime(201801010000));
CHECK(Datetime(201912310000).preYear() == Datetime(201801010000));
CHECK(Datetime(201601010000).preYear() == Datetime(201501010000));
CHECK(Datetime(201612310000).preYear() == Datetime(201501010000));
}
/** @par 检测点 */
TEST_CASE("test_Datetime_related_operator") {
/** @arg 小于比较 */
CHECK(Datetime(200101010000) < Null<Datetime>());
CHECK(Datetime(200101010000) < Datetime::max());
CHECK(Datetime::min() < Datetime(200101010000));
CHECK(Datetime(200101010000) < Datetime(200101020000));
}
/** @} */

View File

@ -0,0 +1,425 @@
/*
* test_iniparser.cpp
*
* Created on: 2019-12-13
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
#include <hikyuu/datetime/TimeDelta.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <fstream>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <hikyuu/serialization/TimeDelta_serialization.h>
using namespace hku;
namespace bt = boost::posix_time;
namespace bd = boost::gregorian;
/**
* @defgroup test_hikyuu_TimeDelta test_hikyuu_TimeDelta
* @ingroup test_hikyuu_datetime_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_TimeDelta") {
/** @arg days 超出限定值 */
CHECK_THROWS_AS(TimeDelta(99999999LL + 1), hku::exception);
CHECK_THROWS_AS(TimeDelta(-99999999LL - 1), hku::exception);
#if !HKU_DISABLE_ASSERT
/** @arg hours 超出限定值 */
CHECK_THROWS_AS(TimeDelta(0, 100001), hku::exception);
CHECK_THROWS_AS(TimeDelta(0, -100001), hku::exception);
/** @arg minutes 超出限定值 */
CHECK_THROWS_AS(TimeDelta(0, 0, 100001), hku::exception);
CHECK_THROWS_AS(TimeDelta(0, 0, -100001), hku::exception);
/** @arg seconds 超出限定值 */
CHECK_THROWS_AS(TimeDelta(0, 0, 0, 8640000), hku::exception);
CHECK_THROWS_AS(TimeDelta(0, 0, 0, -8640000), hku::exception);
/** @arg milliseconds 超出限定值 */
CHECK_THROWS_AS(TimeDelta(0, 0, 0, 0, 8640000000000), hku::exception);
CHECK_THROWS_AS(TimeDelta(0, 0, 0, 0, -8640000000000), hku::exception);
/** @arg microseconds 超出限定值 */
CHECK_THROWS_AS(TimeDelta(0, 0, 0, 0, 0, 8640000000000), hku::exception);
CHECK_THROWS_AS(TimeDelta(0, 0, 0, 0, 0, -8640000000000), hku::exception);
#endif
/** @arg microseconds总值超出限定值 */
CHECK_THROWS_AS(TimeDelta(99999999LL, 23, 59, 60, 999, 999), hku::exception);
/** @arg 正常初始化,时分秒毫秒微秒都在各自的进制范围内 */
TimeDelta td(7, 10, 20, 3, 5, 7);
CHECK(td.days() == 7);
CHECK(td.hours() == 10);
CHECK(td.minutes() == 20);
CHECK(td.seconds() == 3);
CHECK(td.milliseconds() == 5);
CHECK(td.microseconds() == 7);
CHECK(td.isNegative() == false);
/** @arg 正常初始化时大于23 */
td = TimeDelta(0, 24);
CHECK(td.days() == 1);
CHECK(td.hours() == 0);
CHECK(td.minutes() == 0);
CHECK(td.seconds() == 0);
CHECK(td.milliseconds() == 0);
CHECK(td.microseconds() == 0);
CHECK(td.ticks() == 86400000000LL);
CHECK(td.isNegative() == false);
/** @arg 正常初始化分大于59 */
td = TimeDelta(0, 0, 60);
CHECK(td.days() == 0);
CHECK(td.hours() == 1);
CHECK(td.minutes() == 0);
CHECK(td.seconds() == 0);
CHECK(td.milliseconds() == 0);
CHECK(td.microseconds() == 0);
CHECK(td.ticks() == 3600000000LL);
CHECK(td.isNegative() == false);
/** @arg 正常初始化秒大于59 */
td = TimeDelta(0, 0, 0, 60);
CHECK(td.days() == 0);
CHECK(td.hours() == 0);
CHECK(td.minutes() == 1);
CHECK(td.seconds() == 0);
CHECK(td.milliseconds() == 0);
CHECK(td.microseconds() == 0);
CHECK(td.ticks() == 60000000LL);
CHECK(td.isNegative() == false);
/** @arg 负时长初始化, 天数为 -1 */
td = TimeDelta(-1);
CHECK(td.isNegative());
CHECK(td.days() == -1);
CHECK(td.hours() == 0);
CHECK(td.minutes() == 0);
CHECK(td.seconds() == 0);
CHECK(td.milliseconds() == 0);
CHECK(td.microseconds() == 0);
CHECK(td.ticks() == -86400000000LL);
/** @arg 负时长初始化, hours = -1 */
td = TimeDelta(0, -1);
CHECK(td.isNegative());
CHECK(td.days() == -1);
CHECK(td.hours() == 23);
CHECK(td.minutes() == 0);
CHECK(td.seconds() == 0);
CHECK(td.milliseconds() == 0);
CHECK(td.microseconds() == 0);
CHECK(td.ticks() == -60 * 60 * 1000000LL);
/** @arg 负时长初始化, minutes = -1 */
td = TimeDelta(0, 0, -1);
CHECK(td.isNegative());
CHECK(td.days() == -1);
CHECK(td.hours() == 23);
CHECK(td.minutes() == 59);
CHECK(td.seconds() == 0);
CHECK(td.milliseconds() == 0);
CHECK(td.microseconds() == 0);
CHECK(td.ticks() == -60000000LL);
/** @arg 负时长初始化, seconds = -1 */
td = TimeDelta(0, 0, 0, -1);
CHECK(td.isNegative());
CHECK(td.days() == -1);
CHECK(td.hours() == 23);
CHECK(td.minutes() == 59);
CHECK(td.seconds() == 59);
CHECK(td.milliseconds() == 0);
CHECK(td.microseconds() == 0);
CHECK(td.ticks() == -1000000LL);
/** @arg 负时长初始化, milliseconds = -1 */
td = TimeDelta(0, 0, 0, 0, -1);
CHECK(td.isNegative());
CHECK(td.days() == -1);
CHECK(td.hours() == 23);
CHECK(td.minutes() == 59);
CHECK(td.seconds() == 59);
CHECK(td.milliseconds() == 999);
CHECK(td.microseconds() == 0);
CHECK(td.ticks() == -1000LL);
/** @arg 负时长初始化, microseconds = -1 */
td = TimeDelta(0, 0, 0, 0, 0, -1);
CHECK(td.isNegative());
CHECK(td.days() == -1);
CHECK(td.hours() == 23);
CHECK(td.minutes() == 59);
CHECK(td.seconds() == 59);
CHECK(td.milliseconds() == 999);
CHECK(td.microseconds() == 999);
CHECK(td.ticks() == -1LL);
/** @arg 负时长初始化, microseconds = -999 */
td = TimeDelta(0, 0, 0, 0, 0, -999);
CHECK(td.isNegative());
CHECK(td.days() == -1);
CHECK(td.hours() == 23);
CHECK(td.minutes() == 59);
CHECK(td.seconds() == 59);
CHECK(td.milliseconds() == 999);
CHECK(td.microseconds() == 1);
CHECK(td.ticks() == -999LL);
/** @arg 负时长初始化,所有参数均为负数 */
td = TimeDelta(-1, -2, -13, -11, -12, -15);
CHECK(td.isNegative());
CHECK(td.days() == -2);
CHECK(td.hours() == 21);
CHECK(td.minutes() == 46);
CHECK(td.seconds() == 48);
CHECK(td.milliseconds() == 987);
CHECK(td.microseconds() == 985);
CHECK(td.ticks() == -94391012015LL);
/** @arg 正时长初始化,参数正负混合 */
td = TimeDelta(2, -23, -10, 4, 80, -917);
CHECK(td.days() == 1);
CHECK(td.hours() == 0);
CHECK(td.minutes() == 50);
CHECK(td.seconds() == 4);
CHECK(td.milliseconds() == 79);
CHECK(td.microseconds() == 83);
CHECK(td.ticks() == 89404079083LL);
}
/** @par 检测点 */
TEST_CASE("test_TimeDelta_operator") {
/** @arg 相加, 正正相加*/
TimeDelta td = TimeDelta(1, 20, 100, 1, 3, 5) + TimeDelta(30, 3, 2, 4, 5, 6);
CHECK(td.isNegative() == false);
CHECK(td.days() == 32);
CHECK(td.hours() == 0);
CHECK(td.minutes() == 42);
CHECK(td.seconds() == 5);
CHECK(td.milliseconds() == 8);
CHECK(td.microseconds() == 11);
CHECK(td.ticks() == 2767325008011LL);
/** @arg 相加,和为 0 时长 */
td = TimeDelta(1) + TimeDelta(-1);
CHECK(td.isNegative() == false);
CHECK(td.days() == 0);
CHECK(td.hours() == 0);
CHECK(td.minutes() == 0);
CHECK(td.seconds() == 0);
CHECK(td.milliseconds() == 0);
CHECK(td.microseconds() == 0);
CHECK(td.ticks() == 0);
/** @arg 相加,和为负 */
td = TimeDelta(-1) + TimeDelta(0, -1);
CHECK(td.isNegative() == true);
CHECK(td.days() == -2);
CHECK(td.hours() == 23);
CHECK(td.minutes() == 0);
CHECK(td.seconds() == 0);
CHECK(td.milliseconds() == 0);
CHECK(td.microseconds() == 0);
CHECK(td.ticks() == -90000000000LL);
/** @arg + 号 */
CHECK(+TimeDelta(1) == TimeDelta(1));
CHECK(+TimeDelta(-1) == TimeDelta(-1));
/** @arg -号 */
CHECK(-TimeDelta(1) == TimeDelta(-1));
CHECK(-TimeDelta(-1) == TimeDelta(1));
/** @arg 相减结果为0 */
td = TimeDelta(1, 0, 1) - TimeDelta(0, 24, 0, 60);
CHECK(td.isNegative() == false);
CHECK(td.days() == 0);
CHECK(td.hours() == 0);
CHECK(td.minutes() == 0);
CHECK(td.seconds() == 0);
CHECK(td.milliseconds() == 0);
CHECK(td.microseconds() == 0);
CHECK(td.ticks() == 0);
/** @arg 相减,结果为负 */
td = TimeDelta(0, 0, 1) - TimeDelta(0, 1);
CHECK(td.isNegative() == true);
CHECK(td.days() == -1);
CHECK(td.hours() == 23);
CHECK(td.minutes() == 1);
CHECK(td.seconds() == 0);
CHECK(td.milliseconds() == 0);
CHECK(td.microseconds() == 0);
CHECK(td.ticks() == -3540000000LL);
/** @arg 求绝对值 */
td = TimeDelta() - Microseconds(1);
CHECK(td == Microseconds(-1));
CHECK(td.abs() == Microseconds(1));
/** @arg 乘以0 */
td = TimeDelta(1, 1, 3) * 0;
CHECK(td == TimeDelta());
/** @arg 乘以大于0的整数 */
td = TimeDelta(1, 1, 3) * 2;
CHECK(td == TimeDelta(2, 2, 6));
/** @arg 乘以大于0的小数 */
td = TimeDelta(2, 2, 6) * 0.5;
CHECK(td == TimeDelta(1, 1, 3));
/** @arg 乘以小于0的整数 */
td = TimeDelta(1, 1, 3) * -2;
CHECK(td == TimeDelta(-2, -2, -6));
/** @arg 乘以小于0的小数 */
td = TimeDelta(-2, -2, -6) * 0.5;
CHECK(td == TimeDelta(-1, -1, -3));
/** @arg 正 TimeDelat 乘以负数 */
td = TimeDelta(1) * -2;
CHECK(td == TimeDelta(-2));
/** @arg 负 TimeDelat 乘以负数 */
td = TimeDelta(-1) * -2;
CHECK(td == TimeDelta(2));
/** @arg 除以 0 */
CHECK_THROWS_AS(TimeDelta(1) / 0, hku::exception);
/** @arg 正常除法 */
CHECK(TimeDelta(2) / 2 == TimeDelta(1));
CHECK(TimeDelta(2) / TimeDelta(1) == 2);
CHECK(Microseconds(1) / 3 == TimeDelta(0));
CHECK(Microseconds(2) / 3 == Microseconds(1));
/** @arg 地板除 */
CHECK_THROWS_AS(TimeDelta(1).floorDiv(0), hku::exception);
CHECK(TimeDelta(2).floorDiv(2) == TimeDelta(1));
CHECK(Microseconds(1).floorDiv(3) == TimeDelta(0));
CHECK(Microseconds(2).floorDiv(3) == TimeDelta(0));
/** @arg 除以 zero TimeDelta */
CHECK_THROWS_AS(TimeDelta(1) / TimeDelta(), hku::exception);
/** @arg 对零时长取余 */
CHECK_THROWS_AS(TimeDelta(1) % TimeDelta(), hku::exception);
/** @arg 取余 */
CHECK(TimeDelta(3) % TimeDelta(2) == TimeDelta(1));
/** @arg 相等 */
CHECK(TimeDelta(1, 2, 1, 1, 1, 1) == TimeDelta(1, 2, 1, 1, 1, 1));
CHECK(TimeDelta(1) == TimeDelta(0, 24));
CHECK(TimeDelta(-1) == TimeDelta(0, -24));
/** @arg 不等 */
CHECK(TimeDelta(1, 2) != TimeDelta(1));
/** @arg >, <, >=, <= */
CHECK(TimeDelta(1) > TimeDelta(0, 23, 59));
CHECK(TimeDelta(1) >= TimeDelta(0, 23));
CHECK(TimeDelta(0, 0, 0, 0, 0, 1) > TimeDelta());
CHECK(TimeDelta(0, 0, 0, 0, 0, 1) > TimeDelta(0, 0, 0, 0, 0, -1));
CHECK(TimeDelta(1) < TimeDelta(2));
CHECK(TimeDelta(2) <= TimeDelta(2));
/** @arg total_days */
CHECK(TimeDelta(1, 12).total_days() == 1.5);
/** @arg total_hours */
CHECK(TimeDelta(1, 12, 30).total_hours() == 36.5);
/** @arg total_minutes */
CHECK(TimeDelta(1, 12, 30, 30).total_minutes() == (24 + 12) * 60 + 30 + 0.5);
/** @arg total_seconds */
CHECK(TimeDelta(0, 0, 0, 1, 500).total_seconds() == 1.5);
/** @arg total_milliseconds */
CHECK(TimeDelta(0, 0, 0, 0, 1, 500).total_milliseconds() == 1.5);
}
/** @par 检测点 */
TEST_CASE("test_TimeDelta_subclass") {
/** @arg Days */
CHECK(Days(1) == TimeDelta(1));
CHECK(TimeDelta(1) == Days(1));
/** @arg Hours */
CHECK(Hours(1) == TimeDelta(0, 1));
CHECK(TimeDelta(0, 1) == Hours(1));
/** @arg Minutes */
CHECK(Minutes(1) == TimeDelta(0, 0, 1));
CHECK(TimeDelta(0, 0, 1) == Minutes(1));
/** @arg Seconds */
CHECK(Seconds(1) == TimeDelta(0, 0, 0, 1));
CHECK(TimeDelta(0, 0, 0, 1) == Seconds(1));
/** @arg Milliseconds */
CHECK(Milliseconds(1) == TimeDelta(0, 0, 0, 0, 1));
CHECK(TimeDelta(0, 0, 0, 0, 1) == Milliseconds(1));
/** @arg Microseconds */
CHECK(Microseconds(1) == TimeDelta(0, 0, 0, 0, 0, 1));
CHECK(TimeDelta(0, 0, 0, 0, 0, 1) == Microseconds(1));
}
/** @par 检测点 */
TEST_CASE("test_TimeDelta_Datetime_operator") {
/** @arg Datetime + TimeDelta */
Datetime d = Datetime(2019, 12, 18) + TimeDelta(1);
CHECK(d == Datetime(2019, 12, 19));
d = Datetime(2019, 12, 31, 23, 59, 59, 999, 999) + Microseconds(1);
CHECK(d == Datetime(2020, 1, 1));
d = Datetime(2019, 12, 18) + TimeDelta(-1);
CHECK(d == Datetime(2019, 12, 17));
/** @arg Datetime - TimeDelta */
d = Datetime(2019, 12, 18) - TimeDelta(0, 0, 1);
CHECK(d == Datetime(2019, 12, 17, 23, 59));
d = Datetime(2019, 12, 18) - TimeDelta(-2);
CHECK(d == Datetime(2019, 12, 20));
}
/** @par 检测点 */
TEST_CASE("test_TimeDelat_serialize") {
string filename(StockManager::instance().tmpdir());
filename += "/TimeDelta.xml";
TimeDelta td1(1, 2, 3, 4, 5, 6);
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP(td1);
}
TimeDelta td2;
{
std::ifstream ifs(filename);
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(td2);
}
CHECK(td1 == td2);
}
/** @} */

View File

@ -0,0 +1,6 @@
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
using namespace hku;
TEST_CASE("test_temp") {}

View File

@ -0,0 +1,130 @@
/*
* test_Block.cpp
*
* Created on: 201528
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <iostream>
#include <hikyuu/Log.h>
#include <hikyuu/Block.h>
#include <hikyuu/StockManager.h>
using namespace hku;
/**
* @defgroup test_hikyuu_Block test_hikyuu_Block
* @ingroup test_hikyuu_base_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_Block_1") {
Block blk;
/** @arg 默认构造函数,category、name为"" */
CHECK(blk.category() == "");
CHECK(blk.name() == "");
/** @arg 使用category、name构造 */
Block blk2("test", "1");
CHECK(blk2.category() == "test");
CHECK(blk2.name() == "1");
/** @arg 不等判断 */
CHECK((blk != blk2));
/** @arg 空Block比较 */
CHECK_UNARY(blk == Null<Block>());
CHECK_UNARY(blk == Block());
/** @arg 赋值后比较是否相等 */
Block blk3 = blk2;
CHECK((blk2 == blk3));
/** @arg category、name相同但指向不同判定不相等 */
Block blk4("test", "1");
CHECK((blk2 != blk4));
}
/** @par 检测点 */
TEST_CASE("test_Block_2") {
StockManager& sm = StockManager::instance();
Block blk;
/** @arg block为空empty=true / size=0 */
CHECK(blk.empty());
CHECK(blk.size() == 0);
/** @arg 直接加入Stock实例 */
blk.add(sm["sh000001"]);
CHECK(!blk.empty());
CHECK(blk.size() == 1);
blk.add(sm["sz000002"]);
CHECK(!blk.empty());
CHECK(blk.size() == 2);
CHECK(blk.have("sh000001"));
CHECK(blk.have("sz000002"));
CHECK(!blk.have("sz000001"));
CHECK(blk.get("sh000001") == sm["sh000001"]);
CHECK(blk.get("sz000002") == sm["sz000002"]);
/*for (auto iter = blk.begin(); iter != blk.end(); ++iter) {
std::cout << *iter << std::endl;
}*/
/** @arg 已Stock标识加入 */
blk.add("sh000002");
CHECK(!blk.empty());
CHECK(blk.size() == 3);
CHECK(blk.have("sh000002"));
CHECK(blk.get("sh000002") == sm["sh000002"]);
/** @arg 直接删除Stock实例 */
blk.remove(sm["sh000001"]);
CHECK(!blk.empty());
CHECK(blk.size() == 2);
CHECK(blk.have("sh000002"));
CHECK(blk.have("sz000002"));
CHECK(!blk.have("sh000001"));
// CHECK((blk.get("sh000001") == Null<Stock>()));
/** @arg 使用Stock标识进行删除 */
blk.remove("sz000002");
CHECK(!blk.empty());
CHECK(blk.size() == 1);
CHECK(blk.have("sh000002"));
CHECK(!blk.have("sz000002"));
CHECK(!blk.have("sh000001"));
// CHECK((blk.get("sz000002") == Null<Stock>()));
/** @arg 仅剩一条记录时执行删除操作 */
blk.remove("sh000002");
CHECK(blk.empty());
CHECK(blk.size() == 0);
CHECK(!blk.have("sh000002"));
CHECK(!blk.have("sz000002"));
CHECK(!blk.have("sh000001"));
// CHECK((blk.get("sh000002") == Null<Stock>()));
/** @arg 为空时,执行删除操作 */
blk.remove("sh000002");
CHECK(blk.empty());
CHECK(blk.size() == 0);
/** @arg 删除不存在的Stock */
blk.add("sh000002");
CHECK(!blk.have("sz000001"));
blk.remove("sz000001");
CHECK(blk.have("sh000002"));
CHECK(!blk.empty());
CHECK(blk.size() == 1);
/** @arg 测试clear */
CHECK(!blk.empty());
blk.clear();
CHECK(blk.empty());
}
/** @} */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,239 @@
/*
* test_StockManager.cpp
*
* Created on: 2011-11-10
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <boost/filesystem.hpp>
#include <hikyuu/StockManager.h>
#include <hikyuu/utilities/util.h>
#include <hikyuu/utilities/runtimeinfo.h>
#include <hikyuu/Log.h>
using namespace hku;
using namespace boost::filesystem;
/**
* @defgroup test_hikyuu_StockManager test_hikyuu_StockManager
* @ingroup test_hikyuu_base_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_StockManager_size") {
StockManager& sm = StockManager::instance();
/** @arg 检测是否和测试数据中证券数相符 */
CHECK_EQ(sm.size(), 4729);
}
/** @par 检测点 */
TEST_CASE("test_StockManager_getStock") {
StockManager& sm = StockManager::instance();
Stock stock;
Stock null_stock = Null<Stock>();
/** @arg 根据“市场简称证券代码”查询,对应的市场不存在 */
CHECK_EQ(sm.getStock("z000001"), null_stock);
/** @arg 根据“市场简称证券代码”查询,对应的市场存在,但证券代码不存在 */
CHECK_EQ(sm.getStock("sh1000001"), null_stock);
/** @arg 根据“市场简称证券代码”查询正常存在的stock */
stock = sm.getStock("sh000001");
CHECK_EQ(stock.market(), "SH");
CHECK_EQ(stock.code(), "000001");
CHECK_EQ(stock.name(), HKU_STR("上证指数"));
CHECK_EQ(stock.type(), 2);
CHECK_EQ(stock.valid(), true);
CHECK_EQ(stock.startDatetime(), Datetime(199012190000));
CHECK_EQ(stock.lastDatetime(), Null<Datetime>());
CHECK_EQ(stock.tick(), 0.001);
CHECK_EQ(stock.tickValue(), 0.001);
CHECK_EQ(stock.unit(), 1.0);
CHECK_EQ(stock.precision(), 3);
CHECK_EQ(stock.atom(), 1);
CHECK_EQ(stock.minTradeNumber(), 1);
CHECK_EQ(stock.maxTradeNumber(), 1000000);
}
/** @par 检测点 */
TEST_CASE("test_StockManager_getMarketInfo") {
StockManager& sm = StockManager::instance();
/** @arg 查询不存在的市场 */
CHECK_EQ(Null<MarketInfo>(), sm.getMarketInfo("XXX"));
CHECK_EQ(Null<MarketInfo>(), sm.getMarketInfo(""));
/** @arg 查询已存在的市场,市场简称全部大写 */
MarketInfo marketInfo = sm.getMarketInfo("SH");
CHECK_NE(marketInfo, Null<MarketInfo>());
CHECK_EQ(marketInfo.market(), "SH");
CHECK_EQ(marketInfo.code(), "000001");
CHECK_EQ(marketInfo.name(), HKU_STR("上海证劵交易所"));
CHECK_EQ(marketInfo.description(), HKU_STR("上海市场"));
CHECK_EQ(marketInfo.lastDate(), Datetime(201112060000L));
/** @arg 查询已存在的市场,市场简称全部小写 */
marketInfo = sm.getMarketInfo("sh");
CHECK_NE(marketInfo, Null<MarketInfo>());
CHECK_EQ(marketInfo.market(), "SH");
/** @arg 查询已存在的市场,市场简称大小写混写 */
marketInfo = sm.getMarketInfo("Sh");
CHECK_NE(marketInfo, Null<MarketInfo>());
CHECK_EQ(marketInfo.market(), "SH");
}
/** @par 检测点 */
TEST_CASE("test_StockManager_getStockTypeInfo") {
StockManager& sm = StockManager::instance();
StockTypeInfo stockTypeInfo;
/** @arg 查询不存在的type */
CHECK_EQ(sm.getStockTypeInfo(999), Null<StockTypeInfo>());
/** @arg 查询第一条记录即type=0 */
stockTypeInfo = sm.getStockTypeInfo(0);
CHECK_NE(stockTypeInfo, Null<StockTypeInfo>());
CHECK_EQ(stockTypeInfo.type(), 0);
CHECK_EQ(stockTypeInfo.description(), HKU_STR("Block"));
CHECK_EQ(stockTypeInfo.tick(), 100);
CHECK_EQ(stockTypeInfo.precision(), 2);
CHECK_EQ(stockTypeInfo.minTradeNumber(), 100);
CHECK_EQ(stockTypeInfo.maxTradeNumber(), 1000000);
/** @arg 查询最后一条记录即type=8 */
stockTypeInfo = sm.getStockTypeInfo(8);
CHECK_NE(stockTypeInfo, Null<StockTypeInfo>());
CHECK_EQ(stockTypeInfo.type(), 8);
#if !defined(_MSC_VER)
// msvc中文支持不好此处无法编译
CHECK_EQ(stockTypeInfo.description(), HKU_STR("创业板"));
#endif
CHECK_EQ(stockTypeInfo.tick(), 0.01);
CHECK_EQ(stockTypeInfo.precision(), 2);
CHECK_EQ(stockTypeInfo.minTradeNumber(), 100);
CHECK_EQ(stockTypeInfo.maxTradeNumber(), 1000000);
/** @arg 查询正常存在信息 */
stockTypeInfo = sm.getStockTypeInfo(2);
CHECK_NE(stockTypeInfo, Null<StockTypeInfo>());
CHECK_EQ(stockTypeInfo.type(), 2);
CHECK_EQ(stockTypeInfo.description(), HKU_STR("指数"));
CHECK_EQ(stockTypeInfo.tick(), 0.001);
CHECK_EQ(stockTypeInfo.precision(), 3);
CHECK_EQ(stockTypeInfo.minTradeNumber(), 1);
CHECK_EQ(stockTypeInfo.maxTradeNumber(), 1000000);
}
/** @par 检测点 */
TEST_CASE("test_StockManager_getAllMarket") {
StockManager& sm = StockManager::instance();
/** @arg 检测测试数据中的Market */
MarketList result(sm.getAllMarket());
CHECK_EQ(result.size(), 3);
std::vector<string> want_list{"TMP", "SH", "SZ"};
for (auto want : want_list) {
bool found = false;
for (auto i = 0; i < result.size(); i++) {
if (result[i] == want) {
found = true;
break;
}
}
CHECK_UNARY(found);
}
}
/** @par 检测点 */
TEST_CASE("test_StockManager_getBlock") {
if (supportChineseSimple()) {
StockManager& sm = StockManager::instance();
Block result = sm.getBlock("地域板块", "陕西");
CHECK_NE(result.size(), 0);
BlockList blk_list = sm.getBlockList("地域板块");
blk_list = sm.getBlockList();
CHECK_NE(blk_list.size(), 0);
}
}
/** @par 检测点 */
TEST_CASE("test_StockManager_TempCsvStock") {
StockManager& sm = StockManager::instance();
path tmp_dir(sm.tmpdir());
tmp_dir = tmp_dir.parent_path();
string day_filename(tmp_dir.string() + "/test_day_data.csv");
string min_filename(tmp_dir.string() + "/test_min_data.csv");
/** @arg 增加临时增加返还的Stock的基本属性 */
Stock stk = sm.addTempCsvStock("test", day_filename, min_filename);
CHECK_EQ(stk.isNull(), false);
CHECK_EQ(stk.market(), "TMP");
CHECK_EQ(stk.code(), "TEST");
CHECK_EQ(stk.market_code(), "TMPTEST");
CHECK_EQ(stk.getCount(KQuery::DAY), 100);
CHECK_EQ(stk.getCount(KQuery::MIN), 24000);
/** @arg 增加临时增加返还的Stock的KRecord[0](第一个数据)读取*/
KRecord record;
record = stk.getKRecord(0);
CHECK_EQ(record.datetime, Datetime(201703070000));
CHECK_LT((record.openPrice - 3233.09), 0.00001);
CHECK_LT((record.highPrice - 3242.66), 0.00001);
CHECK_LT((record.lowPrice - 3226.82), 0.00001);
CHECK_LT((record.closePrice - 3242.41), 0.00001);
CHECK_LT((record.transAmount - 20993120.6), 0.00001);
CHECK_LT((record.transCount - 164064235.0), 0.00001);
/** @arg 增加临时增加返还的Stock的KRecord[10](中间的数据)读取*/
record = stk.getKRecord(10);
CHECK_EQ(record.datetime, Datetime(201703210000));
CHECK_LT((record.openPrice - 3250.25), 0.00001);
CHECK_LT((record.highPrice - 3262.22), 0.00001);
CHECK_LT((record.lowPrice - 3246.70), 0.00001);
CHECK_LT((record.closePrice - 3261.61)0.00001);
CHECK_LT((record.transAmount - 21912127.0), 0.00001);
CHECK_LT((record.transCount - 162719306.0), 0.00001);
/** @arg 增加临时增加返还的Stock的KRecord[99](最后一个数据)读取*/
record = stk.getKRecord(99);
CHECK_EQ(record.datetime, Datetime(201707310000));
CHECK_LT((record.openPrice - 3252.75), 0.00001);
CHECK_LT((record.highPrice - 3276.95), 0.00001);
CHECK_LT((record.lowPrice - 3251.19), 0.00001);
CHECK_LT((record.closePrice - 3273.03), 0.00001);
CHECK_LT((record.transAmount - 25352591.70), 0.00001);
CHECK_LT((record.transCount - 246039440.0), 0.00001);
/** @arg 使用getStock获取临时加入的Stock */
stk = sm.getStock("tmptest");
CHECK_EQ(stk.isNull(), false);
CHECK_EQ(stk.market(), "TMP");
CHECK_EQ(stk.code(), "TEST");
CHECK_EQ(stk.market_code(), "TMPTEST");
CHECK_EQ(stk.getCount(KQuery::DAY), 100);
CHECK_EQ(stk.getCount(KQuery::MIN), 24000);
/** @arg 使用getStock获取临时加入的Stock的KRecord[10]读取*/
record = stk.getKRecord(10);
CHECK_EQ(record.datetime, Datetime(201703210000));
CHECK_LT((record.openPrice - 3250.25), 0.00001);
CHECK_LT((record.highPrice - 3262.22), 0.00001);
CHECK_LT((record.lowPrice - 3246.70), 0.00001);
CHECK_LT((record.closePrice - 3261.61), 0.00001);
CHECK_LT((record.transAmount - 21912127.0), 0.00001);
CHECK_LT((record.transCount - 162719306.0), 0.00001);
/** @arg 删除临时加入的Stock */
sm.removeTempCsvStock("test");
stk = sm.getStock("tmptest");
CHECK_EQ(stk.isNull(), true);
}
/** @} */

View File

@ -0,0 +1,190 @@
/*
* test_TimeLine.cpp
*
* Created on: 2019210
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
#include <hikyuu/Stock.h>
using namespace hku;
/**
* @defgroup test_hikyuu_TimeLine test_hikyuu_TimeLine
* @ingroup test_hikyuu_base_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_TimeLine_query_by_index") {
StockManager& sm = StockManager::instance();
Stock stock = sm["sz000001"];
KQuery query;
TimeLineList result;
/** @arg start == end > 0*/
query = KQuery(1, 1);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 0);
/** @arg start == end < 0*/
query = KQuery(-1, -1);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 0);
/** @arg start == end == 0*/
query = KQuery(-1, -1);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 0);
/** @arg start > end > 0*/
query = KQuery(1, 3);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201812030931), 10.57, 26962));
CHECK_EQ(result[1], TimeLineRecord(Datetime(201812030932), 10.53, 15407));
/** @arg start < end < 0*/
query = KQuery(-3, -1);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201902011457), 11.20, 46));
CHECK_EQ(result[1], TimeLineRecord(Datetime(201902011458), 11.20, 0));
/** @arg start < end == 0*/
query = KQuery(-3, 0);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 0);
/** @arg 未指定start, end*/
query = KQuery();
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 10320);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201812030930), 10.61, 83391));
CHECK_EQ(result[6516], TimeLineRecord(Datetime(201901111006), 10.18, 2823));
CHECK_EQ(result[10319], TimeLineRecord(Datetime(201902011459), 11.20, 20572));
/** @arg 未指定end*/
query = KQuery(-3);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201902011457), 11.20, 46));
CHECK_EQ(result[1], TimeLineRecord(Datetime(201902011458), 11.20, 0));
CHECK_EQ(result[2], TimeLineRecord(Datetime(201902011459), 11.20, 20572));
query = KQuery(10317);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201902011457), 11.20, 46));
CHECK_EQ(result[1], TimeLineRecord(Datetime(201902011458), 11.20, 0));
CHECK_EQ(result[2], TimeLineRecord(Datetime(201902011459), 11.20, 20572));
/** @arg end 等于总数*/
query = KQuery(10317, 10320);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201902011457), 11.20, 46));
CHECK_EQ(result[1], TimeLineRecord(Datetime(201902011458), 11.20, 0));
CHECK_EQ(result[2], TimeLineRecord(Datetime(201902011459), 11.20, 20572));
/** @arg end 比总数少1*/
query = KQuery(10317, 10319);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201902011457), 11.20, 46));
CHECK_EQ(result[1], TimeLineRecord(Datetime(201902011458), 11.20, 0));
/** @arg end 大于总数*/
query = KQuery(10317, 10321);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201902011457), 11.20, 46));
CHECK_EQ(result[1], TimeLineRecord(Datetime(201902011458), 11.20, 0));
CHECK_EQ(result[2], TimeLineRecord(Datetime(201902011459), 11.20, 20572));
/** @arg start 等于总数*/
query = KQuery(10320);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 0);
/** @arg start 比总数少1*/
query = KQuery(10319);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201902011459), 11.20, 20572));
/** @arg start 大于总数*/
query = KQuery(10321);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 0);
/** @arg start>0, end<0, 且两者有交集*/
query = KQuery(10317, -1);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201902011457), 11.20, 46));
CHECK_EQ(result[1], TimeLineRecord(Datetime(201902011458), 11.20, 0));
/** @arg start<0, end>0, 且两者有交集*/
query = KQuery(-3, 10319);
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201902011457), 11.20, 46));
CHECK_EQ(result[1], TimeLineRecord(Datetime(201902011458), 11.20, 0));
}
/** @par 检测点 */
TEST_CASE("test_TimeLine_query_by_date") {
StockManager& sm = StockManager::instance();
Stock stock = sm["sz000001"];
KQuery query;
TimeLineList result;
/** @arg start 小于数据起始日期未指定end*/
query = KQueryByDate(Datetime(201812030000));
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 10320);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201812030930), 10.61, 83391));
CHECK_EQ(result[6516], TimeLineRecord(Datetime(201901111006), 10.18, 2823));
CHECK_EQ(result[10319], TimeLineRecord(Datetime(201902011459), 11.20, 20572));
/** @arg start 等于数据起始日期未指定end*/
query = KQueryByDate(Datetime(201812030930));
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 10320);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201812030930), 10.61, 83391));
CHECK_EQ(result[6516], TimeLineRecord(Datetime(201901111006), 10.18, 2823));
CHECK_EQ(result[10319], TimeLineRecord(Datetime(201902011459), 11.20, 20572));
/** @arg start大于数据起始日期未指定end*/
query = KQueryByDate(Datetime(201902011457));
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201902011457), 11.20, 46));
CHECK_EQ(result[1], TimeLineRecord(Datetime(201902011458), 11.20, 0));
CHECK_EQ(result[2], TimeLineRecord(Datetime(201902011459), 11.20, 20572));
/** @arg start 等于 end*/
query = KQueryByDate(Datetime(201902011457), Datetime(201902011457));
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 0);
/** @arg start, end 都在数据范围内, 且end为最后一条记录日期 */
query = KQueryByDate(Datetime(201902011457), Datetime(201902011459));
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201902011457), 11.20, 46));
CHECK_EQ(result[1], TimeLineRecord(Datetime(201902011458), 11.20, 0));
/** @arg start 在数据范围内, end大于最后一条记录日期 */
query = KQueryByDate(Datetime(201902011457), Datetime(201902020000));
result = stock.getTimeLineList(query);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], TimeLineRecord(Datetime(201902011457), 11.20, 46));
CHECK_EQ(result[1], TimeLineRecord(Datetime(201902011458), 11.20, 0));
CHECK_EQ(result[2], TimeLineRecord(Datetime(201902011459), 11.20, 20572));
}
/** @} */

View File

@ -0,0 +1,190 @@
/*
* test_TransList.cpp
*
* Created on: 2019-2-11
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
#include <hikyuu/Stock.h>
using namespace hku;
/**
* @defgroup test_hikyuu_TransList test_hikyuu_TransList
* @ingroup test_hikyuu_base_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_TransList_query_by_index") {
StockManager& sm = StockManager::instance();
Stock stock = sm["sz000001"];
KQuery query;
TransList result;
/** @arg start == end > 0*/
query = KQuery(1, 1);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 0);
/** @arg start == end < 0*/
query = KQuery(-1, -1);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 0);
/** @arg start == end == 0*/
query = KQuery(-1, -1);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 0);
/** @arg start > end > 0*/
query = KQuery(1, 3);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 1, 9, 30, 2), 11.21, 1339, TransRecord::BUY));
CHECK_EQ(result[1], TransRecord(Datetime(2019, 2, 1, 9, 30, 5), 11.21, 5263, TransRecord::BUY));
/** @arg start < end < 0*/
query = KQuery(-3, -1);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 11, 14, 56, 59), 11.20, 210, TransRecord::SELL));
CHECK_EQ(result[1], TransRecord(Datetime(2019, 2, 11, 14, 57, 2), 11.20, 31, TransRecord::SELL));
/** @arg start < end == 0*/
query = KQuery(-3, 0);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 0);
/** @arg 未指定start, end*/
query = KQuery();
result = stock.getTransList(query);
CHECK_EQ(result.size(), 8884);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 1, 9, 25, 2), 11.20, 15714, TransRecord::AUCTION));
CHECK_EQ(result[563], TransRecord(Datetime(2019, 2, 1, 9, 58, 47), 11.04, 91, TransRecord::BUY));
CHECK_EQ(result[8883], TransRecord(Datetime(2019, 2, 11, 15, 0, 0), 11.21, 5794, TransRecord::AUCTION));
/** @arg 未指定end*/
query = KQuery(-3);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 11, 14, 56, 59), 11.20, 210, TransRecord::SELL));
CHECK_EQ(result[1], TransRecord(Datetime(2019, 2, 11, 14, 57, 2), 11.20, 31, TransRecord::SELL));
CHECK_EQ(result[2], TransRecord(Datetime(2019, 2, 11, 15, 0, 0), 11.21, 5794, TransRecord::AUCTION));
query = KQuery(8881);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 11, 14, 56, 59), 11.20, 210, TransRecord::SELL));
CHECK_EQ(result[1], TransRecord(Datetime(2019, 2, 11, 14, 57, 2), 11.20, 31, TransRecord::SELL));
CHECK_EQ(result[2], TransRecord(Datetime(2019, 2, 11, 15, 0, 0), 11.21, 5794, TransRecord::AUCTION));
/** @arg end 等于总数*/
query = KQuery(8881, 8884);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 11, 14, 56, 59), 11.20, 210, TransRecord::SELL));
CHECK_EQ(result[1], TransRecord(Datetime(2019, 2, 11, 14, 57, 2), 11.20, 31, TransRecord::SELL));
CHECK_EQ(result[2], TransRecord(Datetime(2019, 2, 11, 15, 0, 0), 11.21, 5794, TransRecord::AUCTION));
/** @arg end 比总数少1*/
query = KQuery(8881, 8883);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 11, 14, 56, 59), 11.20, 210, TransRecord::SELL));
CHECK_EQ(result[1], TransRecord(Datetime(2019, 2, 11, 14, 57, 2), 11.20, 31, TransRecord::SELL));
/** @arg end 大于总数*/
query = KQuery(8881, 8885);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 11, 14, 56, 59), 11.20, 210, TransRecord::SELL));
CHECK_EQ(result[1], TransRecord(Datetime(2019, 2, 11, 14, 57, 2), 11.20, 31, TransRecord::SELL));
CHECK_EQ(result[2], TransRecord(Datetime(2019, 2, 11, 15, 0, 0), 11.21, 5794, TransRecord::AUCTION));
/** @arg start 等于总数*/
query = KQuery(8884);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 0);
/** @arg start 比总数少1*/
query = KQuery(8883);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 11, 15, 0, 0), 11.21, 5794, TransRecord::AUCTION));
/** @arg start 大于总数*/
query = KQuery(8885);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 0);
/** @arg start>0, end<0, 且两者有交集*/
query = KQuery(8881, -1);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 11, 14, 56, 59), 11.20, 210, TransRecord::SELL));
CHECK_EQ(result[1], TransRecord(Datetime(2019, 2, 11, 14, 57, 2), 11.20, 31, TransRecord::SELL));
/** @arg start<0, end>0, 且两者有交集*/
query = KQuery(-3, 8883);
result = stock.getTransList(query);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 11, 14, 56, 59), 11.20, 210, TransRecord::SELL));
CHECK_EQ(result[1], TransRecord(Datetime(2019, 2, 11, 14, 57, 2), 11.20, 31, TransRecord::SELL));
}
/** @par 检测点 */
TEST_CASE("test_TransList_query_by_date") {
StockManager& sm = StockManager::instance();
Stock stock = sm["sz000001"];
KQuery query;
TransList result;
/** @arg start 小于数据起始日期未指定end*/
query = KQueryByDate(Datetime(201812030000));
result = stock.getTransList(query);
CHECK_EQ(result.size(), 8884);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 1, 9, 25, 2), 11.20, 15714, TransRecord::AUCTION));
CHECK_EQ(result[563], TransRecord(Datetime(2019, 2, 1, 9, 58, 47), 11.04, 91, TransRecord::BUY));
CHECK_EQ(result[8883], TransRecord(Datetime(2019, 2, 11, 15, 0, 0), 11.21, 5794, TransRecord::AUCTION));
/** @arg start 等于数据起始日期未指定end*/
query = KQueryByDate(Datetime(2019, 2, 1, 9, 25, 2));
result = stock.getTransList(query);
CHECK_EQ(result.size(), 8884);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 1, 9, 25, 2), 11.20, 15714, TransRecord::AUCTION));
CHECK_EQ(result[563], TransRecord(Datetime(2019, 2, 1, 9, 58, 47), 11.04, 91, TransRecord::BUY));
CHECK_EQ(result[8883], TransRecord(Datetime(2019, 2, 11, 15, 0, 0), 11.21, 5794, TransRecord::AUCTION));
/** @arg start大于数据起始日期未指定end*/
query = KQueryByDate(Datetime(2019, 2, 11, 14, 56, 59));
result = stock.getTransList(query);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 11, 14, 56, 59), 11.20, 210, TransRecord::SELL));
CHECK_EQ(result[1], TransRecord(Datetime(2019, 2, 11, 14, 57, 2), 11.20, 31, TransRecord::SELL));
CHECK_EQ(result[2], TransRecord(Datetime(2019, 2, 11, 15, 0, 0), 11.21, 5794, TransRecord::AUCTION));
/** @arg start 等于 end*/
query = KQueryByDate(Datetime(2019, 2, 11, 14, 56, 59), Datetime(2019, 2, 11, 14, 56, 59));
result = stock.getTransList(query);
CHECK_EQ(result.size(), 0);
/** @arg start, end 都在数据范围内, 且end为最后一条记录日期 */
query = KQueryByDate(Datetime(2019, 2, 11, 14, 56, 59), Datetime(2019, 2, 11, 15, 0, 0));
result = stock.getTransList(query);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 11, 14, 56, 59), 11.20, 210, TransRecord::SELL));
CHECK_EQ(result[1], TransRecord(Datetime(2019, 2, 11, 14, 57, 2), 11.20, 31, TransRecord::SELL));
/** @arg start 在数据范围内, end大于最后一条记录日期 */
query = KQueryByDate(Datetime(2019, 2, 11, 14, 56, 59), Datetime(201902120000));
result = stock.getTransList(query);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], TransRecord(Datetime(2019, 2, 11, 14, 56, 59), 11.20, 210, TransRecord::SELL));
CHECK_EQ(result[1], TransRecord(Datetime(2019, 2, 11, 14, 57, 2), 11.20, 31, TransRecord::SELL));
CHECK_EQ(result[2], TransRecord(Datetime(2019, 2, 11, 15, 0, 0), 11.21, 5794, TransRecord::AUCTION));
}
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/ABS.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ABS ) {
TEST_CASE("test_ABS") {
Indicator result;
PriceList a;
@ -38,26 +32,25 @@ BOOST_AUTO_TEST_CASE( test_ABS ) {
Indicator data = PRICELIST(a);
result = ABS(data);
BOOST_CHECK(result.name() == "ABS");
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == -data[i]);
CHECK_UNARY(result.name() == "ABS");
CHECK_UNARY(result.discard() == 0);
for (int i = 0; i < 10; ++i) {
CHECK_UNARY(result[i] == -data[i]);
}
result = ABS(-11);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 11);
CHECK_UNARY(result.size() == 1);
CHECK_UNARY(result.discard() == 0);
CHECK_UNARY(result[0] == 11);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ABS_export ) {
TEST_CASE("test_ABS_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/ABS.xml";
@ -78,15 +71,13 @@ BOOST_AUTO_TEST_CASE( test_ABS_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_UNARY(x1.size() == x2.size());
CHECK_UNARY(x1.discard() == x2.discard());
CHECK_UNARY(x1.getResultNumber() == x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]).epsilon(0.00001));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_ACOS.cpp
*
* Copyright (c) 2019 hikyuu.org
*
*
* Created on: 2019-5-1
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/ACOS.h>
@ -29,37 +23,36 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ACOS ) {
TEST_CASE("test_ACOS") {
Indicator result;
PriceList a;
for (int i = 0; i < 10; ++i) {
a.push_back(i/10);
a.push_back(i / 10);
}
Indicator data = PRICELIST(a);
result = ACOS(data);
BOOST_CHECK(result.name() == "ACOS");
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == std::acos(data[i]));
CHECK_EQ(result.name(), "ACOS");
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], std::acos(data[i]));
}
result = ACOS(-0.1);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == std::acos(-0.1));
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], std::acos(-0.1));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ACOS_export ) {
TEST_CASE("test_ACOS_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/ACOS.xml";
@ -80,20 +73,18 @@ BOOST_AUTO_TEST_CASE( test_ACOS_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "ACOS");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "ACOS");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
if (std::isnan(x1[i])) {
BOOST_CHECK(std::isnan(x2[i]));
CHECK_UNARY(std::isnan(x2[i]));
} else {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/AD.h>
@ -26,31 +19,30 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_AD ) {
TEST_CASE("test_AD") {
StockManager& sm = StockManager::instance();
Stock stk = getStock("SH600004");
KQuery query = KQueryByIndex(-10);
KData k = stk.getKData(query);
Indicator ad = AD(k);
BOOST_CHECK(ad.name() == "AD");
BOOST_CHECK(ad.size() == k.size());
BOOST_CHECK(ad.discard() == 0);
BOOST_CHECK(ad[0] == 0);
BOOST_CHECK_CLOSE(ad[1], 458.65, 0.1);
BOOST_CHECK_CLOSE(ad[2], 63.99, 0.1);
BOOST_CHECK_CLOSE(ad[5], 30.77, 0.1);
CHECK_EQ(ad.name(), "AD");
CHECK_EQ(ad.size(), k.size());
CHECK_EQ(ad.discard(), 0);
CHECK_EQ(ad[0], 0);
CHECK_EQ(ad[1], doctest::Approx(458.65).epsilon(0.1));
CHECK_EQ(ad[2], doctest::Approx(63.99).epsilon(0.1));
CHECK_EQ(ad[5], doctest::Approx(30.77).epsilon(0.1));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_AD_export ) {
TEST_CASE("test_AD_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/AD.xml";
@ -72,15 +64,14 @@ BOOST_AUTO_TEST_CASE( test_AD_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "AD");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "AD");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_ALIGN.cpp
*
* Copyright (c) 2019 hikyuu.org
*
*
* Created on: 2019-5-1
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/ALIGN.h>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ALIGN ) {
TEST_CASE("test_ALIGN") {
Indicator result;
Stock stk = getStock("sh000001");
@ -42,35 +36,35 @@ BOOST_AUTO_TEST_CASE( test_ALIGN ) {
DatetimeList ref;
Indicator data = PRICELIST(a);
result = ALIGN(data, ref);
BOOST_CHECK(result.name() == "ALIGN");
BOOST_CHECK(ref.size() == 0);
BOOST_CHECK(result.size() == 0);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.name(), "ALIGN");
CHECK_EQ(ref.size(), 0);
CHECK_EQ(result.size(), 0);
CHECK_EQ(result.discard(), 0);
/** @arg 输入指标本身和上下文无关,和参考日期列表等长 */
ref = stk.getDatetimeList(KQuery(-10));
data = PRICELIST(a);
result = ALIGN(data, ref);
BOOST_CHECK(result.name() == "ALIGN");
BOOST_CHECK(result.size() == ref.size());
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.name(), "ALIGN");
CHECK_EQ(result.size(), ref.size());
CHECK_EQ(result.discard(), 0);
DatetimeList result_dates = result.getDatetimeList();
for (int i = 0; i < result.size(); i++) {
BOOST_CHECK(result[i] == data[i]);
BOOST_CHECK(result_dates[i] == ref[i]);
CHECK_EQ(result[i], data[i]);
CHECK_EQ(result_dates[i], ref[i]);
}
/** @arg 输入指标本身和上下文无关,且长度长于参考日期列表 */
a.push_back(11);
data = PRICELIST(a);
result = ALIGN(data, ref);
BOOST_CHECK(result.name() == "ALIGN");
BOOST_CHECK(result.size() == ref.size());
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.name(), "ALIGN");
CHECK_EQ(result.size(), ref.size());
CHECK_EQ(result.discard(), 0);
result_dates = result.getDatetimeList();
for (int i = 0; i < result.size(); i++) {
BOOST_CHECK(result[i] == data[i+1]);
BOOST_CHECK(result_dates[i] == ref[i]);
CHECK_EQ(result[i], data[i + 1]);
CHECK_EQ(result_dates[i], ref[i]);
}
/** @arg 输入指标本身和上下文无关,且长度小于参考日期列表 */
@ -78,28 +72,28 @@ BOOST_AUTO_TEST_CASE( test_ALIGN ) {
a.push_back(1);
data = PRICELIST(a);
result = ALIGN(data, ref);
BOOST_CHECK(result.name() == "ALIGN");
BOOST_CHECK(result.size() == ref.size());
BOOST_CHECK(result.discard() == 9);
CHECK_EQ(result.name(), "ALIGN");
CHECK_EQ(result.size(), ref.size());
CHECK_EQ(result.discard(), 9);
result_dates = result.getDatetimeList();
for (int i = 0; i < result.discard(); i++) {
BOOST_CHECK(std::isnan(result[i]));
BOOST_CHECK(result_dates[i] == ref[i]);
CHECK_UNARY(std::isnan(result[i]));
CHECK_EQ(result_dates[i], ref[i]);
}
BOOST_CHECK(result[9] == 1);
BOOST_CHECK(result_dates[9] == ref[9]);
CHECK_EQ(result[9], 1);
CHECK_EQ(result_dates[9], ref[9]);
/** @arg 输入指标本身和上下文无关且长度为0 */
a.clear();
data = PRICELIST(a);
result = ALIGN(data, ref);
BOOST_CHECK(result.name() == "ALIGN");
BOOST_CHECK(result.size() == ref.size());
BOOST_CHECK(result.discard() == ref.size());
CHECK_EQ(result.name(), "ALIGN");
CHECK_EQ(result.size(), ref.size());
CHECK_EQ(result.discard(), ref.size());
result_dates = result.getDatetimeList();
for (int i = 0; i < result.discard(); i++) {
BOOST_CHECK(std::isnan(result[i]));
BOOST_CHECK(result_dates[i] == ref[i]);
CHECK_UNARY(std::isnan(result[i]));
CHECK_EQ(result_dates[i], ref[i]);
}
/** @arg ind对应日期全部大于参考日期 */
@ -110,13 +104,13 @@ BOOST_AUTO_TEST_CASE( test_ALIGN ) {
ref.push_back(Datetime(201901030000));
data = CLOSE(k);
result = ALIGN(data, ref);
BOOST_CHECK(result.name() == "ALIGN");
BOOST_CHECK(result.size() == ref.size());
BOOST_CHECK(result.discard() == ref.size());
CHECK_EQ(result.name(), "ALIGN");
CHECK_EQ(result.size(), ref.size());
CHECK_EQ(result.discard(), ref.size());
result_dates = result.getDatetimeList();
for (int i = 0; i < result.discard(); i++) {
BOOST_CHECK(std::isnan(result[i]));
BOOST_CHECK(result_dates[i] == ref[i]);
CHECK_UNARY(std::isnan(result[i]));
CHECK_EQ(result_dates[i], ref[i]);
}
/** @arg ind对应日期全部小于参考日期 */
@ -126,26 +120,26 @@ BOOST_AUTO_TEST_CASE( test_ALIGN ) {
ref.push_back(Datetime(191901030000));
data = CLOSE(k);
result = ALIGN(data, ref);
BOOST_CHECK(result.name() == "ALIGN");
BOOST_CHECK(result.size() == ref.size());
BOOST_CHECK(result.discard() == ref.size());
CHECK_EQ(result.name(), "ALIGN");
CHECK_EQ(result.size(), ref.size());
CHECK_EQ(result.discard(), ref.size());
result_dates = result.getDatetimeList();
for (int i = 0; i < result.discard(); i++) {
BOOST_CHECK(std::isnan(result[i]));
BOOST_CHECK(result_dates[i] == ref[i]);
CHECK_UNARY(std::isnan(result[i]));
CHECK_EQ(result_dates[i], ref[i]);
}
/** @arg ind对应日期等于参考日期 */
ref = k.getDatetimeList();
data = CLOSE(k);
result = ALIGN(data, ref);
BOOST_CHECK(result.name() == "ALIGN");
BOOST_CHECK(result.size() == ref.size());
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.name(), "ALIGN");
CHECK_EQ(result.size(), ref.size());
CHECK_EQ(result.discard(), 0);
result_dates = result.getDatetimeList();
for (int i = 0; i < result.size(); i++) {
BOOST_CHECK(result[i] == data[i]);
BOOST_CHECK(result_dates[i] == ref[i]);
CHECK_EQ(result[i], data[i]);
CHECK_EQ(result_dates[i], ref[i]);
}
/** @arg ind对应部分日期 */
@ -159,29 +153,28 @@ BOOST_AUTO_TEST_CASE( test_ALIGN ) {
ref.push_back(Datetime(201112100000));
data = CLOSE(k);
result = ALIGN(data, ref);
BOOST_CHECK(result.name() == "ALIGN");
BOOST_CHECK(result.size() == ref.size());
BOOST_CHECK(result.discard() == 1);
BOOST_CHECK(std::isnan(result[0]));
BOOST_CHECK_CLOSE(result[1], 2395.07, 0.01);
BOOST_CHECK_CLOSE(result[2], 2397.55, 0.01);
BOOST_CHECK(std::isnan(result[3]));
BOOST_CHECK_CLOSE(result[4], 2325.91, 0.01);
BOOST_CHECK(std::isnan(result[5]));
BOOST_CHECK(std::isnan(result[6]));
CHECK_EQ(result.name(), "ALIGN");
CHECK_EQ(result.size(), ref.size());
CHECK_EQ(result.discard(), 1);
CHECK_UNARY(std::isnan(result[0]));
CHECK_EQ(result[1], doctest::Approx(2395.07));
CHECK_EQ(result[2], doctest::Approx(2397.55));
CHECK_UNARY(std::isnan(result[3]));
CHECK_EQ(result[4], doctest::Approx(2325.91));
CHECK_UNARY(std::isnan(result[5]));
CHECK_UNARY(std::isnan(result[6]));
for (int i = 0; i < result.size(); i++) {
BOOST_CHECK(result.getDatetime(i) == ref[i]);
CHECK_EQ(result.getDatetime(i), ref[i]);
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ALIGN_export ) {
TEST_CASE("test_ALIGN_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/ALIGN.xml";
@ -202,16 +195,14 @@ BOOST_AUTO_TEST_CASE( test_ALIGN_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "ALIGN");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "ALIGN");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/AMA.h>
@ -28,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_AMA ) {
TEST_CASE("test_AMA") {
Indicator result;
PriceList d;
@ -54,50 +47,49 @@ BOOST_AUTO_TEST_CASE( test_AMA ) {
d.push_back(6347);
Indicator ind = PRICELIST(d);
BOOST_CHECK(ind.size() == 20);
CHECK_EQ(ind.size(), 20);
result = AMA(ind, 10, 2, 30);
BOOST_CHECK(result.getParam<int>("n") == 10);
BOOST_CHECK(result.getParam<int>("fast_n") == 2);
BOOST_CHECK(result.getParam<int>("slow_n") == 30);
BOOST_CHECK(result.size() == 20);
BOOST_CHECK(result.empty() == false);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.getResultNumber() == 2);
BOOST_CHECK(result[0] == 6063);
BOOST_CHECK(std::fabs(result[9] - 6103.6781) < 0.000001);
BOOST_CHECK(std::fabs(result[10] - 6120.760197) < 0.000001);
BOOST_CHECK(std::fabs(result[18] - 6216.376893) < 0.000001);
BOOST_CHECK(std::fabs(result[19] - 6239.100742) < 0.000001);
CHECK_EQ(result.getParam<int>("n"), 10);
CHECK_EQ(result.getParam<int>("fast_n"), 2);
CHECK_EQ(result.getParam<int>("slow_n"), 30);
CHECK_EQ(result.size(), 20);
CHECK_EQ(result.empty(), false);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.getResultNumber(), 2);
CHECK_EQ(result[0], 6063);
CHECK_LT(std::fabs(result[9] - 6103.6781), 0.000001);
CHECK_LT(std::fabs(result[10] - 6120.760197), 0.000001);
CHECK_LT(std::fabs(result[18] - 6216.376893), 0.000001);
CHECK_LT(std::fabs(result[19] - 6239.100742), 0.000001);
BOOST_CHECK(result.get(0,1) == 1.0);
BOOST_CHECK(std::fabs(result.get(9, 1) - 0.557895) < 0.000001);
BOOST_CHECK(std::fabs(result.get(10, 1) - 0.611111) < 0.000001);
BOOST_CHECK(std::fabs(result.get(11, 1) - 0.826484) < 0.000001);
BOOST_CHECK(std::fabs(result.get(18, 1) - 0.517799) < 0.000001);
BOOST_CHECK(std::fabs(result.get(19, 1) - 0.585526) < 0.000001);
CHECK_EQ(result.get(0, 1), 1.0);
CHECK_LT(std::fabs(result.get(9, 1) - 0.557895), 0.000001);
CHECK_LT(std::fabs(result.get(10, 1) - 0.611111), 0.000001);
CHECK_LT(std::fabs(result.get(11, 1) - 0.826484), 0.000001);
CHECK_LT(std::fabs(result.get(18, 1) - 0.517799), 0.000001);
CHECK_LT(std::fabs(result.get(19, 1) - 0.585526), 0.000001);
/** @arg operator() */
Indicator ama = AMA(10, 2, 30);
BOOST_CHECK(ama.size() == 0);
CHECK_EQ(ama.size(), 0);
Indicator expect = AMA(ind, 10, 2, 30);
result = ama(ind);
BOOST_CHECK(result.size() == expect.size());
BOOST_CHECK(result.getResultNumber() == expect.getResultNumber());
BOOST_CHECK(result.discard() == expect.discard());
CHECK_EQ(result.size(), expect.size());
CHECK_EQ(result.getResultNumber(), expect.getResultNumber());
CHECK_EQ(result.discard(), expect.discard());
for (size_t i = 0; i < expect.size(); ++i) {
BOOST_CHECK(result[i] == expect[i]);
BOOST_CHECK(result.get(i, 1) == expect.get(i, 1));
CHECK_EQ(result[i], expect[i]);
CHECK_EQ(result.get(i, 1), expect.get(i, 1));
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_AMA_export ) {
TEST_CASE("test_AMA_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/AMA.xml";
@ -118,15 +110,14 @@ BOOST_AUTO_TEST_CASE( test_AMA_export ) {
ia >> BOOST_SERIALIZATION_NVP(ma2);
}
BOOST_CHECK(ma1.size() == ma2.size());
BOOST_CHECK(ma1.discard() == ma2.discard());
BOOST_CHECK(ma1.getResultNumber() == ma2.getResultNumber());
CHECK_EQ(ma1.size(), ma2.size());
CHECK_EQ(ma1.discard(), ma2.discard());
CHECK_EQ(ma1.getResultNumber(), ma2.getResultNumber());
for (size_t i = 0; i < ma1.size(); ++i) {
BOOST_CHECK_CLOSE(ma1.get(i, 0), ma2.get(i, 0), 0.00001);
BOOST_CHECK_CLOSE(ma1.get(i, 1), ma2.get(i, 1), 0.00001);
CHECK_EQ(ma1.get(i, 0), doctest::Approx(ma2.get(i, 0)));
CHECK_EQ(ma1.get(i, 1), doctest::Approx(ma2.get(i, 1)));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_ASIN.cpp
*
* Copyright (c) 2019 hikyuu.org
*
*
* Created on: 2019-5-1
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/ASIN.h>
@ -29,42 +23,41 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ASIN ) {
TEST_CASE("test_ASIN") {
Indicator result;
PriceList a;
for (int i = 0; i < 10; ++i) {
a.push_back(i/10);
a.push_back(i / 10);
}
Indicator data = PRICELIST(a);
result = ASIN(data);
BOOST_CHECK(result.name() == "ASIN");
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == std::asin(data[i]));
CHECK_EQ(result.name(), "ASIN");
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], std::asin(data[i]));
}
result = ASIN(-0.1);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == std::asin(-0.1));
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], std::asin(-0.1));
result = ASIN(1.01);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(std::isnan(result[0]));
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_UNARY(std::isnan(result[0]));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ASIN_export ) {
TEST_CASE("test_ASIN_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/ASIN.xml";
@ -85,20 +78,18 @@ BOOST_AUTO_TEST_CASE( test_ASIN_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "ASIN");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "ASIN");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
if (std::isnan(x1[i])) {
BOOST_CHECK(std::isnan(x2[i]));
CHECK_UNARY(std::isnan(x2[i]));
} else {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_ATAN.cpp
*
* Copyright (c) 2019 hikyuu.org
*
*
* Created on: 2019-5-1
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/ATAN.h>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ATAN ) {
TEST_CASE("test_ATAN") {
Indicator result;
PriceList a;
@ -40,26 +34,25 @@ BOOST_AUTO_TEST_CASE( test_ATAN ) {
Indicator data = PRICELIST(a);
result = ATAN(data);
BOOST_CHECK(result.name() == "ATAN");
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == std::atan(data[i]));
CHECK_EQ(result.name(), "ATAN");
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], std::atan(data[i]));
}
result = ATAN(-11);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == std::atan(-11));
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], std::atan(-11));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ATAN_export ) {
TEST_CASE("test_ATAN_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/ATAN.xml";
@ -80,16 +73,14 @@ BOOST_AUTO_TEST_CASE( test_ATAN_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "ATAN");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "ATAN");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_BACKSET.cpp
*
* Copyright (c) 2019 hikyuu.org
*
*
* Created on: 2019-5-13
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/BACKSET.h>
@ -29,30 +23,30 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_BACKSET ) {
TEST_CASE("test_BACKSET") {
Indicator result;
/** @arg 未指定输入ind */
result = BACKSET();
BOOST_CHECK(result.name() == "BACKSET");
BOOST_CHECK(result.size() == 0);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.name(), "BACKSET");
CHECK_EQ(result.size(), 0);
CHECK_EQ(result.discard(), 0);
/** @arg n = 1, total = 0*/
PriceList a;
Indicator data = PRICELIST(a);
result = BACKSET(data, 1);
BOOST_CHECK(result.size() == 0);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 0);
CHECK_EQ(result.discard(), 0);
/** @arg n = 1, total = 1*/
a.push_back(0);
data = PRICELIST(a);
result = BACKSET(data, 1);
BOOST_CHECK(result.name() == "BACKSET");
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 0);
CHECK_EQ(result.name(), "BACKSET");
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
/** @arg n = 1, total > 1*/
a.push_back(1);
@ -62,18 +56,18 @@ BOOST_AUTO_TEST_CASE( test_BACKSET ) {
data = PRICELIST(a);
result = BACKSET(data, 1);
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < data.size(); i++) {
BOOST_CHECK(result[i] == data[i]);
CHECK_EQ(result[i], data[i]);
}
/** @arg n = 1, total = 0*/
a.clear();
data = PRICELIST(a);
result = BACKSET(data, 1);
BOOST_CHECK(result.size() == 0);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 0);
CHECK_EQ(result.discard(), 0);
/** @arg n = 2, total = 2*/
a.clear();
@ -81,20 +75,20 @@ BOOST_AUTO_TEST_CASE( test_BACKSET ) {
a.push_back(0);
data = PRICELIST(a);
result = BACKSET(data, 2);
BOOST_CHECK(result.size() == 2);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 1);
BOOST_CHECK(result[1] == 0);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 1);
CHECK_EQ(result[1], 0);
a.clear();
a.push_back(0);
a.push_back(1);
data = PRICELIST(a);
result = BACKSET(data, 2);
BOOST_CHECK(result.size() == 2);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 1);
BOOST_CHECK(result[1] == 1);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 1);
CHECK_EQ(result[1], 1);
/** @arg n = 3 */
a.clear();
@ -111,29 +105,28 @@ BOOST_AUTO_TEST_CASE( test_BACKSET ) {
a.push_back(1);
data = PRICELIST(a);
result = BACKSET(data, 3);
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 1);
BOOST_CHECK(result[1] == 1);
BOOST_CHECK(result[2] == 0);
BOOST_CHECK(result[3] == 0);
BOOST_CHECK(result[4] == 1);
BOOST_CHECK(result[5] == 1);
BOOST_CHECK(result[6] == 1);
BOOST_CHECK(result[7] == 1);
BOOST_CHECK(result[8] == 1);
BOOST_CHECK(result[9] == 1);
BOOST_CHECK(result[10] == 1);
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 1);
CHECK_EQ(result[1], 1);
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 0);
CHECK_EQ(result[4], 1);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[6], 1);
CHECK_EQ(result[7], 1);
CHECK_EQ(result[8], 1);
CHECK_EQ(result[9], 1);
CHECK_EQ(result[10], 1);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_BACKSET_export ) {
TEST_CASE("test_BACKSET_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/BACKSET.xml";
@ -154,16 +147,14 @@ BOOST_AUTO_TEST_CASE( test_BACKSET_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "BACKSET");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "BACKSET");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_BARSCOUNT.cpp
*
* Copyright (c) 2019 hikyuu.org
*
*
* Created on: 2019-5-12
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/BARSLAST.h>
@ -30,7 +24,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_BARSCOUNT ) {
TEST_CASE("test_BARSCOUNT") {
Indicator result;
/** @arg 输入指标,未关联上下文 */
@ -43,44 +37,43 @@ BOOST_AUTO_TEST_CASE( test_BARSCOUNT ) {
Indicator data = PRICELIST(a, 2);
result = BARSCOUNT(data);
BOOST_CHECK(result.name() == "BARSCOUNT");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 2);
BOOST_CHECK(std::isnan(result[0]));
BOOST_CHECK(std::isnan(result[1]));
BOOST_CHECK(result[2] == 1);
BOOST_CHECK(result[3] == 2);
CHECK_EQ(result.name(), "BARSCOUNT");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 2);
CHECK_UNARY(std::isnan(result[0]));
CHECK_UNARY(std::isnan(result[1]));
CHECK_EQ(result[2], 1);
CHECK_EQ(result[3], 2);
/** @arg 输入指标为日线 CLOSE */
Stock stk = getStock("sz000001");
KData k = stk.getKData(KQuery(-100));
result = BARSCOUNT(CLOSE(k));
BOOST_CHECK(result.name() == "BARSCOUNT");
BOOST_CHECK(result.size() == k.size());
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 4838);
BOOST_CHECK(result[99] == 4937);
CHECK_EQ(result.name(), "BARSCOUNT");
CHECK_EQ(result.size(), k.size());
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 4838);
CHECK_EQ(result[99], 4937);
/** @arg 输入指标为分钟线 CLOSE */
k = stk.getKData(KQueryByDate(Datetime(200209020000), Datetime(200209050000), KQuery::MIN));
result = BARSCOUNT(CLOSE(k));
BOOST_CHECK(result.name() == "BARSCOUNT");
BOOST_CHECK(result.size() == k.size());
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 1);
BOOST_CHECK(result[1] == 2);
BOOST_CHECK(result[477] == 239);
BOOST_CHECK(result[478] == 240);
CHECK_EQ(result.name(), "BARSCOUNT");
CHECK_EQ(result.size(), k.size());
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 1);
CHECK_EQ(result[1], 2);
CHECK_EQ(result[477], 239);
CHECK_EQ(result[478], 240);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_BARSCOUNT_export ) {
TEST_CASE("test_BARSCOUNT_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/BARSCOUNT.xml";
@ -101,16 +94,14 @@ BOOST_AUTO_TEST_CASE( test_BARSCOUNT_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "BARSCOUNT");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "BARSCOUNT");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -0,0 +1,129 @@
/*
* test_BARSLAST.cpp
*
* Copyright (c) 2019 hikyuu.org
*
* Created on: 2019-5-4
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/BARSLAST.h>
#include <hikyuu/indicator/crt/KDATA.h>
#include <hikyuu/indicator/crt/PRICELIST.h>
using namespace hku;
/**
* @defgroup test_indicator_BARSLAST test_indicator_BARSLAST
* @ingroup test_hikyuu_indicator_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_BARSLAST") {
Indicator result;
PriceList a;
a.push_back(0);
a.push_back(0);
a.push_back(0);
a.push_back(1);
a.push_back(0);
a.push_back(0);
a.push_back(1);
Indicator data = PRICELIST(a);
result = BARSLAST(data);
CHECK_EQ(result.name(), "BARSLAST");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 3);
CHECK_UNARY(std::isnan(result[0]));
CHECK_UNARY(std::isnan(result[1]));
CHECK_UNARY(std::isnan(result[2]));
CHECK_EQ(result[3], 0);
CHECK_EQ(result[4], 1);
CHECK_EQ(result[5], 2);
CHECK_EQ(result[6], 0);
a.insert(a.begin(), 1);
data = PRICELIST(a);
result = BARSLAST(data);
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 1);
CHECK_EQ(result[2], 2);
CHECK_EQ(result[3], 3);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[6], 2);
CHECK_EQ(result[7], 0);
a.push_back(0.0);
data = PRICELIST(a);
result = BARSLAST(data);
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 1);
CHECK_EQ(result[2], 2);
CHECK_EQ(result[3], 3);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[6], 2);
CHECK_EQ(result[7], 0);
CHECK_EQ(result[8], 1);
result = BARSLAST(-11);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
result = BARSLAST(0);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 1);
CHECK_UNARY(std::isnan(result[0]));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
TEST_CASE("test_BARSLAST_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/BARSLAST.xml";
Stock stock = sm.getStock("sh000001");
KData kdata = stock.getKData(KQuery(-20));
Indicator x1 = BARSLAST(CLOSE(kdata));
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP(x1);
}
Indicator x2;
{
std::ifstream ifs(filename);
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(x2);
}
CHECK_EQ(x2.name(), "BARSLAST");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_BARSSINCE.cpp
*
* Copyright (c) 2019 hikyuu.org
*
*
* Created on: 2019-5-4
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/BARSSINCE.h>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_BARSSINCE ) {
TEST_CASE("test_BARSSINCE") {
Indicator result;
PriceList a;
@ -40,29 +34,28 @@ BOOST_AUTO_TEST_CASE( test_BARSSINCE ) {
Indicator data = PRICELIST(a);
result = BARSSINCE(data);
BOOST_CHECK(result.name() == "BARSSINCE");
BOOST_CHECK(result.size() == 5);
BOOST_CHECK(result.discard() == 1);
BOOST_CHECK(std::isnan(result[0]));
BOOST_CHECK(result[1] == 0);
BOOST_CHECK(result[2] == 1);
BOOST_CHECK(result[3] == 2);
BOOST_CHECK(result[4] == 3);
CHECK_EQ(result.name(), "BARSSINCE");
CHECK_EQ(result.size(), 5);
CHECK_EQ(result.discard(), 1);
CHECK_UNARY(std::isnan(result[0]));
CHECK_EQ(result[1], 0);
CHECK_EQ(result[2], 1);
CHECK_EQ(result[3], 2);
CHECK_EQ(result[4], 3);
result = BARSSINCE(-11);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 0);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_BARSSINCE_export ) {
TEST_CASE("test_BARSSINCE_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/BARSSINCE.xml";
@ -83,16 +76,14 @@ BOOST_AUTO_TEST_CASE( test_BARSSINCE_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "BARSSINCE");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "BARSSINCE");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/BETWEEN.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_BETWEEN ) {
TEST_CASE("test_BETWEEN") {
Indicator result;
/** @arg 所有参数均为 ind */
@ -51,61 +45,60 @@ BOOST_AUTO_TEST_CASE( test_BETWEEN ) {
Indicator c = PRICELIST(cval);
result = BETWEEN(a, b, c);
BOOST_CHECK(result.name() == "BETWEEN");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result[4] == 1);
CHECK_EQ(result.name(), "BETWEEN");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result[4], 1);
for (int i = 0; i < 10; i++) {
if (i != 4) {
BOOST_CHECK(result[i] == 0);
CHECK_EQ(result[i], 0);
}
}
/** @arg a 为indb、c均为数字 */
result = BETWEEN(a, 5, 3);
BOOST_CHECK(result.name() == "BETWEEN");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result[4] == 1);
CHECK_EQ(result.name(), "BETWEEN");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result[4], 1);
for (int i = 0; i < 10; i++) {
if (i != 4) {
BOOST_CHECK(result[i] == 0);
CHECK_EQ(result[i], 0);
}
}
/** @arg a 为数字b、c中一个为 ind一个为数字 */
result = BETWEEN(2, b, 2);
BOOST_CHECK(result.name() == "BETWEEN");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == 10);
CHECK_EQ(result.name(), "BETWEEN");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 10);
for (int i = 0; i < 10; i++) {
BOOST_CHECK(result[i] == 0);
CHECK_EQ(result[i], 0);
}
result = BETWEEN(3, b, 2);
BOOST_CHECK(result.name() == "BETWEEN");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == 10);
CHECK_EQ(result.name(), "BETWEEN");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 10);
for (int i = 0; i < 10; i++) {
BOOST_CHECK(result[i] == 1);
CHECK_EQ(result[i], 1);
}
/** @arg a、b、c均为数字 */
result = BETWEEN(1, 2, 3);
BOOST_CHECK(result.name() == "BETWEEN");
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 0);
CHECK_EQ(result.name(), "BETWEEN");
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_BETWEEN_export ) {
TEST_CASE("test_BETWEEN_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/BETWEEN.xml";
@ -132,7 +125,7 @@ BOOST_AUTO_TEST_CASE( test_BETWEEN_export ) {
Indicator b = PRICELIST(bval);
Indicator c = PRICELIST(cval);
Indicator x1 = BETWEEN(a, b, c);
Indicator x1 = BETWEEN(a, b, c);
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);
@ -146,15 +139,13 @@ BOOST_AUTO_TEST_CASE( test_BETWEEN_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/CEILING.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_CEILING ) {
TEST_CASE("test_CEILING") {
Indicator result;
PriceList a;
@ -38,27 +32,26 @@ BOOST_AUTO_TEST_CASE( test_CEILING ) {
Indicator data = PRICELIST(a);
result = CEILING(data);
BOOST_CHECK(result.name() == "CEILING");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == 3);
BOOST_CHECK_CLOSE(result[0], 14, 0.01);
BOOST_CHECK_CLOSE(result[1], 1, 0.01);
BOOST_CHECK_CLOSE(result[2], 2, 0.01);
CHECK_EQ(result.name(), "CEILING");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], doctest::Approx(14));
CHECK_EQ(result[1], doctest::Approx(1));
CHECK_EQ(result[2], doctest::Approx(2));
result = CEILING(-11.15);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK_CLOSE(result[0], -11, 0.01);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], doctest::Approx(-11));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_CEILING_export ) {
TEST_CASE("test_CEILING_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/CEILING.xml";
@ -79,16 +72,14 @@ BOOST_AUTO_TEST_CASE( test_CEILING_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "CEILING");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "CEILING");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_COS.cpp
*
* Copyright (c) 2019 hikyuu.org
*
*
* Created on: 2019-5-1
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/COS.h>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_COS ) {
TEST_CASE("test_COS") {
Indicator result;
PriceList a;
@ -40,26 +34,25 @@ BOOST_AUTO_TEST_CASE( test_COS ) {
Indicator data = PRICELIST(a);
result = COS(data);
BOOST_CHECK(result.name() == "COS");
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == std::cos(data[i]));
CHECK_EQ(result.name(), "COS");
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], std::cos(data[i]));
}
result = COS(-11);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == std::cos(-11));
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], std::cos(-11));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_COS_export ) {
TEST_CASE("test_COS_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/COS.xml";
@ -80,16 +73,14 @@ BOOST_AUTO_TEST_CASE( test_COS_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "COS");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "COS");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/KDATA.h>
@ -28,16 +21,16 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_COUNT ) {
TEST_CASE("test_COUNT") {
/** @arg n > 0 */
Indicator C = CLOSE();
Indicator x = COUNT(C > REF(C, 1), 5);
x.setContext(getStock("sh600004"), KQuery(-8));
BOOST_CHECK(x.size() == 8);
BOOST_CHECK(x.discard() == 5);
BOOST_CHECK(x[5] == 3);
BOOST_CHECK(x[6] == 2);
BOOST_CHECK(x[7] == 2);
CHECK_EQ(x.size(), 8);
CHECK_EQ(x.discard(), 5);
CHECK_EQ(x[5], 3);
CHECK_EQ(x[6], 2);
CHECK_EQ(x[7], 2);
/*C.setContext(getStock("sh600004"), KQuery(-8));
for (int i = 1; i < 8 ; i++) {
std::cout << i << " " << C[i-1] << " " << C[i] << " " << x[i] << std::endl;
@ -46,26 +39,25 @@ BOOST_AUTO_TEST_CASE( test_COUNT ) {
/** @arg n == 0 */
x = COUNT(C > REF(C, 1), 0);
x.setContext(getStock("sh600004"), KQuery(-8));
BOOST_CHECK(x.size() == 8);
BOOST_CHECK(x.discard() == 1);
BOOST_CHECK(std::isnan(x[0]));
BOOST_CHECK(x[1] == 1);
BOOST_CHECK(x[2] == 2);
BOOST_CHECK(x[3] == 2);
BOOST_CHECK(x[4] == 3);
BOOST_CHECK(x[5] == 3);
BOOST_CHECK(x[6] == 3);
BOOST_CHECK(x[7] == 4);
CHECK_EQ(x.size(), 8);
CHECK_EQ(x.discard(), 1);
CHECK_UNARY(std::isnan(x[0]));
CHECK_EQ(x[1], 1);
CHECK_EQ(x[2], 2);
CHECK_EQ(x[3], 2);
CHECK_EQ(x[4], 3);
CHECK_EQ(x[5], 3);
CHECK_EQ(x[6], 3);
CHECK_EQ(x[7], 4);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_COUNT_export ) {
TEST_CASE("test_COUNT_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/COUNT.xml";
@ -87,14 +79,13 @@ BOOST_AUTO_TEST_CASE( test_COUNT_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: Administrator
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/KDATA.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_CVAL ) {
TEST_CASE("test_CVAL") {
Indicator result;
PriceList d;
@ -54,60 +48,58 @@ BOOST_AUTO_TEST_CASE( test_CVAL ) {
/** @arg operator(ind) */
Indicator ind = PRICELIST(d);
BOOST_CHECK(ind.size() == 20);
CHECK_EQ(ind.size(), 20);
result = CVAL(ind, 100);
BOOST_CHECK(result.getParam<double>("value") == 100);
BOOST_CHECK(result.size() == 20);
BOOST_CHECK(result.empty() == false);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.getResultNumber() == 1);
CHECK_EQ(result.getParam<double>("value"), 100);
CHECK_EQ(result.size(), 20);
CHECK_EQ(result.empty(), false);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.getResultNumber(), 1);
for (size_t i = 0; i < ind.size(); ++i) {
BOOST_CHECK(result[i] == 100);
CHECK_EQ(result[i], 100);
}
/** @arg operator() */
result = CVAL(100);
BOOST_CHECK(result.getParam<double>("value") == 100);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.empty() == false);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result[0] == 100);
CHECK_EQ(result.getParam<double>("value"), 100);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.empty(), false);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result[0], 100);
/** @arg 测试discard, 未指定ind discard=2 */
result = CVAL(100, 2);
BOOST_CHECK(result.getParam<double>("value") == 100);
BOOST_CHECK(result.getParam<int>("discard") == 2);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.empty() == false);
BOOST_CHECK(result.discard() == 1);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(std::isnan(result[0]));
CHECK_EQ(result.getParam<double>("value"), 100);
CHECK_EQ(result.getParam<int>("discard"), 2);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.empty(), false);
CHECK_EQ(result.discard(), 1);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_UNARY(std::isnan(result[0]));
/** @arg 测试discard, ind discard=2 */
ind = PRICELIST(d);
BOOST_CHECK(ind.size() == 20);
CHECK_EQ(ind.size(), 20);
result = CVAL(ind, 100, 2);
BOOST_CHECK(result.getParam<double>("value") == 100);
BOOST_CHECK(result.getParam<int>("discard") == 2);
BOOST_CHECK(result.size() == 20);
BOOST_CHECK(result.empty() == false);
BOOST_CHECK(result.discard() == 2);
BOOST_CHECK(result.getResultNumber() == 1);
CHECK_EQ(result.getParam<double>("value"), 100);
CHECK_EQ(result.getParam<int>("discard"), 2);
CHECK_EQ(result.size(), 20);
CHECK_EQ(result.empty(), false);
CHECK_EQ(result.discard(), 2);
CHECK_EQ(result.getResultNumber(), 1);
for (size_t i = result.discard(); i < ind.size(); ++i) {
BOOST_CHECK(result[i] == 100);
CHECK_EQ(result[i], 100);
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_CVAL_export ) {
TEST_CASE("test_CVAL_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/CVAL.xml";
@ -128,15 +120,13 @@ BOOST_AUTO_TEST_CASE( test_CVAL_export ) {
ia >> BOOST_SERIALIZATION_NVP(ma2);
}
BOOST_CHECK(ma1.size() == ma2.size());
BOOST_CHECK(ma1.discard() == ma2.discard());
BOOST_CHECK(ma1.getResultNumber() == ma2.getResultNumber());
CHECK_EQ(ma1.size(), ma2.size());
CHECK_EQ(ma1.discard(), ma2.discard());
CHECK_EQ(ma1.getResultNumber(), ma2.getResultNumber());
for (size_t i = 0; i < ma1.size(); ++i) {
BOOST_CHECK_CLOSE(ma1[i], ma2[i], 0.00001);
CHECK_EQ(ma1[i], doctest::Approx(ma2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/KDATA.h>
@ -28,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_DIFF ) {
TEST_CASE("test_DIFF") {
/** @arg 正常测试 */
PriceList d;
for (size_t i = 0; i < 10; ++i) {
@ -37,34 +30,33 @@ BOOST_AUTO_TEST_CASE( test_DIFF ) {
Indicator ind = PRICELIST(d);
Indicator diff = DIFF(ind);
BOOST_CHECK(diff.size() == 10);
BOOST_CHECK(diff.discard() == 1);
BOOST_CHECK(std::isnan(diff[0]));
CHECK_EQ(diff.size(), 10);
CHECK_EQ(diff.discard(), 1);
CHECK_UNARY(std::isnan(diff[0]));
for (size_t i = 1; i < 10; ++i) {
BOOST_CHECK(diff[i] == d[i] - d[i-1]);
CHECK_EQ(diff[i], d[i] - d[i - 1]);
}
/** @arg operator */
diff = DIFF();
Indicator expect = DIFF(ind);
Indicator result = diff(ind);
BOOST_CHECK(expect.size() == result.size());
CHECK_EQ(expect.size(), result.size());
for (size_t i = 0; i < result.discard(); i++) {
BOOST_CHECK(std::isnan(result[i]));
CHECK_UNARY(std::isnan(result[i]));
}
for (size_t i = result.discard(); i < expect.size(); ++i) {
BOOST_CHECK(result[i] == expect[i]);
CHECK_EQ(result[i], expect[i]);
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_DIFF_export ) {
TEST_CASE("test_DIFF_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/DIFF.xml";
@ -85,15 +77,13 @@ BOOST_AUTO_TEST_CASE( test_DIFF_export ) {
ia >> BOOST_SERIALIZATION_NVP(ma2);
}
BOOST_CHECK(ma1.size() == ma2.size());
BOOST_CHECK(ma1.discard() == ma2.discard());
BOOST_CHECK(ma1.getResultNumber() == ma2.getResultNumber());
CHECK_EQ(ma1.size(), ma2.size());
CHECK_EQ(ma1.discard(), ma2.discard());
CHECK_EQ(ma1.getResultNumber(), ma2.getResultNumber());
for (size_t i = ma1.discard(); i < ma1.size(); ++i) {
BOOST_CHECK_CLOSE(ma1[i], ma2[i], 0.00001);
CHECK_EQ(ma1[i], doctest::Approx(ma2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_DROPNA.cpp
*
* Copyright (c) 2019 hikyuu.org
*
*
* Created on: 2019-5-28
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/DROPNA.h>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_DROPNA ) {
TEST_CASE("test_DROPNA") {
Indicator result;
PriceList a;
@ -41,10 +35,10 @@ BOOST_AUTO_TEST_CASE( test_DROPNA ) {
/** @arg 无 nan 值 */
result = DROPNA(data);
BOOST_CHECK(result.name() == "DROPNA");
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == data[i]);
CHECK_EQ(result.name(), "DROPNA");
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], data[i]);
}
/** @arg 全部为 nan 值 */
@ -55,8 +49,8 @@ BOOST_AUTO_TEST_CASE( test_DROPNA ) {
data = VALUE(a);
result = DROPNA(data);
BOOST_CHECK(result.size() == 0);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 0);
CHECK_EQ(result.discard(), 0);
/** @arg 中间存在 nan 值 */
a.push_back(Null<price_t>());
@ -66,20 +60,19 @@ BOOST_AUTO_TEST_CASE( test_DROPNA ) {
a.push_back(Null<price_t>());
data = VALUE(a);
result = DROPNA(data);
BOOST_CHECK(result.size() == 2);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 12);
BOOST_CHECK(result[1] == 15);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 12);
CHECK_EQ(result[1], 15);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_DROPNA_export ) {
TEST_CASE("test_DROPNA_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/DROPNA.xml";
@ -100,16 +93,14 @@ BOOST_AUTO_TEST_CASE( test_DROPNA_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "DROPNA");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "DROPNA");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/EMA.h>
@ -28,7 +22,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_EMA ) {
TEST_CASE("test_EMA") {
PriceList d;
for (int i = 0; i < 30; ++i) {
d.push_back(i);
@ -37,48 +31,47 @@ BOOST_AUTO_TEST_CASE( test_EMA ) {
/** @arg n = 1 */
Indicator data = PRICELIST(d);
Indicator ema = EMA(data, 1);
BOOST_CHECK(ema.discard() == 0);
BOOST_CHECK(ema.size() == 30);
BOOST_CHECK(ema[0] == 0.0);
BOOST_CHECK(ema[10] == 10.0);
BOOST_CHECK(ema[29] == 29.0);
CHECK_EQ(ema.discard(), 0);
CHECK_EQ(ema.size(), 30);
CHECK_EQ(ema[0], 0.0);
CHECK_EQ(ema[10], 10.0);
CHECK_EQ(ema[29], 29.0);
/** @arg n = 2 */
ema = EMA(data, 2);
BOOST_CHECK(ema.discard() == 0);
BOOST_CHECK(ema.size() == 30);
BOOST_CHECK(ema[0] == 0.0);
BOOST_CHECK(std::fabs(ema[1] - 0.66667) < 0.0001);
BOOST_CHECK(std::fabs(ema[2] - 1.55556) < 0.0001);
BOOST_CHECK(std::fabs(ema[3] - 2.51852) < 0.0001);
BOOST_CHECK(std::fabs(ema[4] - 3.50617) < 0.0001);
CHECK_EQ(ema.discard(), 0);
CHECK_EQ(ema.size(), 30);
CHECK_EQ(ema[0], 0.0);
CHECK_LT(std::fabs(ema[1] - 0.66667), 0.0001);
CHECK_LT(std::fabs(ema[2] - 1.55556), 0.0001);
CHECK_LT(std::fabs(ema[3] - 2.51852), 0.0001);
CHECK_LT(std::fabs(ema[4] - 3.50617), 0.0001);
/** @arg n = 10 */
ema = EMA(data, 10);
BOOST_CHECK(ema.discard() == 0);
BOOST_CHECK(ema.size() == 30);
BOOST_CHECK(ema[0] == 0.0);
BOOST_CHECK(std::fabs(ema[1] - 0.18182) < 0.0001);
BOOST_CHECK(std::fabs(ema[2] - 0.51240) < 0.0001);
CHECK_EQ(ema.discard(), 0);
CHECK_EQ(ema.size(), 30);
CHECK_EQ(ema[0], 0.0);
CHECK_LT(std::fabs(ema[1] - 0.18182), 0.0001);
CHECK_LT(std::fabs(ema[2] - 0.51240), 0.0001);
/** @arg operator() */
Indicator ma = MA(data, 2);
Indicator expect = EMA(ma, 2);
ema = EMA(2);
Indicator result = ema(ma);
BOOST_CHECK(result.size() == expect.size());
CHECK_EQ(result.size(), expect.size());
for (size_t i = 0; i < expect.size(); ++i) {
BOOST_CHECK(result[i] == expect[i]);
CHECK_EQ(result[i], expect[i]);
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_EMA_export ) {
TEST_CASE("test_EMA_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/EMA.xml";
@ -99,14 +92,13 @@ BOOST_AUTO_TEST_CASE( test_EMA_export ) {
ia >> BOOST_SERIALIZATION_NVP(ma2);
}
BOOST_CHECK(ma1.size() == ma2.size());
BOOST_CHECK(ma1.discard() == ma2.discard());
BOOST_CHECK(ma1.getResultNumber() == ma2.getResultNumber());
CHECK_EQ(ma1.size(), ma2.size());
CHECK_EQ(ma1.discard(), ma2.discard());
CHECK_EQ(ma1.getResultNumber(), ma2.getResultNumber());
for (size_t i = 0; i < ma1.size(); ++i) {
BOOST_CHECK_CLOSE(ma1[i], ma2[i], 0.00001);
CHECK_EQ(ma1[i], doctest::Approx(ma2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/CVAL.h>
@ -28,7 +22,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_EVERY ) {
TEST_CASE("test_EVERY") {
Indicator result;
PriceList a;
@ -43,59 +37,59 @@ BOOST_AUTO_TEST_CASE( test_EVERY ) {
/** @arg n=0 */
result = EVERY(data, 0);
BOOST_CHECK(result.name() == "EVERY");
BOOST_CHECK(result.discard() == data.size()-1);
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result[5] == 0);
CHECK_EQ(result.name(), "EVERY");
CHECK_EQ(result.discard(), data.size() - 1);
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result[5], 0);
for (int i = 0; i < 5; i++) {
BOOST_CHECK(std::isnan(result[i]));
CHECK_UNARY(std::isnan(result[i]));
}
/** @arg n=1, total>1 */
result = EVERY(data, 1);
BOOST_CHECK(result.name() == "EVERY");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == data.size());
CHECK_EQ(result.name(), "EVERY");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), data.size());
for (int i = 0; i < data.size(); ++i) {
BOOST_CHECK(result[i] == data[i]);
CHECK_EQ(result[i], data[i]);
}
/** @arg n=1, total=1 */
result = EVERY(CVAL(1), 1);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 1);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 1);
result = EVERY(CVAL(0), 1);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 0);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
/** @arg n > 1, total = n */
result = EVERY(data, 6);
BOOST_CHECK(result.name() == "EVERY");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 5);
BOOST_CHECK(result[5] == 0);
CHECK_EQ(result.name(), "EVERY");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 5);
CHECK_EQ(result[5], 0);
/** @arg n > 1, total < n */
result = EVERY(data, 7);
BOOST_CHECK(result.name() == "EVERY");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 6);
CHECK_EQ(result.name(), "EVERY");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 6);
/** @arg n > 1, total > n */
result = EVERY(data, 3);
BOOST_CHECK(result.name() == "EVERY");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 2);
CHECK_EQ(result.name(), "EVERY");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 2);
for (int i = 0; i < result.discard(); i++) {
BOOST_CHECK(std::isnan(result[i]));
CHECK_UNARY(std::isnan(result[i]));
}
BOOST_CHECK(result[2] == 0);
BOOST_CHECK(result[3] == 0);
BOOST_CHECK(result[4] == 0);
BOOST_CHECK(result[5] == 0);
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 0);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 0);
a.push_back(1);
a.push_back(1);
@ -104,37 +98,36 @@ BOOST_AUTO_TEST_CASE( test_EVERY ) {
data = PRICELIST(a);
result = EVERY(data, 3);
BOOST_CHECK(result.name() == "EVERY");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 2);
CHECK_EQ(result.name(), "EVERY");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 2);
for (int i = 0; i < result.discard(); i++) {
BOOST_CHECK(std::isnan(result[i]));
CHECK_UNARY(std::isnan(result[i]));
}
BOOST_CHECK(result[2] == 0);
BOOST_CHECK(result[3] == 0);
BOOST_CHECK(result[4] == 0);
BOOST_CHECK(result[5] == 0);
BOOST_CHECK(result[6] == 0);
BOOST_CHECK(result[7] == 0);
BOOST_CHECK(result[8] == 1);
BOOST_CHECK(result[9] == 1);
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 0);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 0);
CHECK_EQ(result[6], 0);
CHECK_EQ(result[7], 0);
CHECK_EQ(result[8], 1);
CHECK_EQ(result[9], 1);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_EVERY_export ) {
TEST_CASE("test_EVERY_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/EVERY.xml";
Stock stock = sm.getStock("sh000001");
KData kdata = stock.getKData(KQuery(-20));
Indicator x1 = EVERY(CLOSE(kdata)>OPEN(kdata));
Indicator x1 = EVERY(CLOSE(kdata) > OPEN(kdata));
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);
@ -148,16 +141,14 @@ BOOST_AUTO_TEST_CASE( test_EVERY_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "EVERY");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "EVERY");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -4,14 +4,7 @@
* Created on: 2019-4-19
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/CVAL.h>
@ -28,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_EXIST ) {
TEST_CASE("test_EXIST") {
Indicator result;
PriceList a;
@ -43,58 +36,58 @@ BOOST_AUTO_TEST_CASE( test_EXIST ) {
/** @arg n=0 */
result = EXIST(data, 0);
BOOST_CHECK(result.discard() == data.size()-1);
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result[5] == 1);
CHECK_EQ(result.discard(), data.size() - 1);
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result[5], 1);
for (int i = 0; i < data.discard(); ++i) {
BOOST_CHECK(std::isnan(result[i]));
CHECK_UNARY(std::isnan(result[i]));
}
/** @arg n=1, total>1 */
result = EXIST(data, 1);
BOOST_CHECK(result.name() == "EXIST");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == data.size());
CHECK_EQ(result.name(), "EXIST");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), data.size());
for (int i = 0; i < data.size(); ++i) {
BOOST_CHECK(result[i] == data[i]);
CHECK_EQ(result[i], data[i]);
}
/** @arg n=1, total=1 */
result = EXIST(CVAL(1), 1);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 1);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 1);
result = EXIST(CVAL(0), 1);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 0);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
/** @arg n > 1, total = n */
result = EXIST(data, 6);
BOOST_CHECK(result.name() == "EXIST");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 5);
BOOST_CHECK(result[5] == 1);
CHECK_EQ(result.name(), "EXIST");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 5);
CHECK_EQ(result[5], 1);
/** @arg n > 1, total < n */
result = EXIST(data, 7);
BOOST_CHECK(result.name() == "EXIST");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 6);
CHECK_EQ(result.name(), "EXIST");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 6);
/** @arg n > 1, total > n */
result = EXIST(data, 3);
BOOST_CHECK(result.name() == "EXIST");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 2);
CHECK_EQ(result.name(), "EXIST");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 2);
for (int i = 0; i < result.discard(); i++) {
BOOST_CHECK(std::isnan(result[i]));
CHECK_UNARY(std::isnan(result[i]));
}
BOOST_CHECK(result[2] == 1);
BOOST_CHECK(result[3] == 1);
BOOST_CHECK(result[4] == 1);
BOOST_CHECK(result[5] == 1);
CHECK_EQ(result[2], 1);
CHECK_EQ(result[3], 1);
CHECK_EQ(result[4], 1);
CHECK_EQ(result[5], 1);
a.push_back(0);
a.push_back(0);
@ -103,37 +96,36 @@ BOOST_AUTO_TEST_CASE( test_EXIST ) {
data = PRICELIST(a);
result = EXIST(data, 3);
BOOST_CHECK(result.name() == "EXIST");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 2);
CHECK_EQ(result.name(), "EXIST");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 2);
for (int i = 0; i < result.discard(); i++) {
BOOST_CHECK(std::isnan(result[i]));
CHECK_UNARY(std::isnan(result[i]));
}
BOOST_CHECK(result[2] == 1);
BOOST_CHECK(result[3] == 1);
BOOST_CHECK(result[4] == 1);
BOOST_CHECK(result[5] == 1);
BOOST_CHECK(result[6] == 1);
BOOST_CHECK(result[7] == 0);
BOOST_CHECK(result[8] == 0);
BOOST_CHECK(result[9] == 0);
CHECK_EQ(result[2], 1);
CHECK_EQ(result[3], 1);
CHECK_EQ(result[4], 1);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[6], 1);
CHECK_EQ(result[7], 0);
CHECK_EQ(result[8], 0);
CHECK_EQ(result[9], 0);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_EXIST_export ) {
TEST_CASE("test_EXIST_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/EXIST.xml";
Stock stock = sm.getStock("sh000001");
KData kdata = stock.getKData(KQuery(-20));
Indicator x1 = EXIST(CLOSE(kdata)>OPEN(kdata));
Indicator x1 = EXIST(CLOSE(kdata) > OPEN(kdata));
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);
@ -147,16 +139,14 @@ BOOST_AUTO_TEST_CASE( test_EXIST_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "EXIST");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "EXIST");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/EXP.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_EXP ) {
TEST_CASE("test_EXP") {
Indicator result;
PriceList a;
@ -38,26 +32,25 @@ BOOST_AUTO_TEST_CASE( test_EXP ) {
Indicator data = PRICELIST(a);
result = EXP(data);
BOOST_CHECK(result.name() == "EXP");
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == std::exp(data[i]));
CHECK_EQ(result.name(), "EXP");
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], std::exp(data[i]));
}
result = EXP(1);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == std::exp(1));
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], std::exp(1));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_EXP_export ) {
TEST_CASE("test_EXP_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/EXP.xml";
@ -78,19 +71,17 @@ BOOST_AUTO_TEST_CASE( test_EXP_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
if (std::isinf(x1[i])) {
BOOST_CHECK(std::isinf(x2[i]));
CHECK_UNARY(std::isinf(x2[i]));
} else {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -0,0 +1,174 @@
/*
* test_FILTER.cpp
*
* Created on: 2019-5-4
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/CVAL.h>
#include <hikyuu/indicator/crt/FILTER.h>
#include <hikyuu/indicator/crt/KDATA.h>
#include <hikyuu/indicator/crt/PRICELIST.h>
using namespace hku;
/**
* @defgroup test_indicator_FILTER test_indicator_FILTER
* @ingroup test_hikyuu_indicator_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_FILTER") {
Indicator result;
PriceList a;
a.push_back(0);
a.push_back(1);
a.push_back(0);
a.push_back(1);
a.push_back(1);
a.push_back(1);
a.push_back(1);
a.push_back(0);
Indicator data = PRICELIST(a);
/** @arg n=0 */
result = FILTER(data, 0);
CHECK_EQ(result.name(), "FILTER");
CHECK_EQ(result.discard(), data.size());
CHECK_EQ(result.size(), data.size());
/** @arg n=1, total>1 */
result = FILTER(data, 1);
CHECK_EQ(result.name(), "FILTER");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 1);
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 1);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[6], 0);
CHECK_EQ(result[7], 0);
/** @arg n=1, total=1 */
result = FILTER(CVAL(1), 1);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 1);
result = FILTER(CVAL(0), 1);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
/** @arg n > 1, total = n */
result = FILTER(data, 8);
CHECK_EQ(result.name(), "FILTER");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 1);
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 0);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 0);
CHECK_EQ(result[6], 0);
CHECK_EQ(result[7], 0);
/** @arg n > 1, total < n */
result = FILTER(data, 10);
CHECK_EQ(result.name(), "FILTER");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 1);
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 0);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 0);
CHECK_EQ(result[6], 0);
CHECK_EQ(result[7], 0);
/** @arg n > 1, total > n */
result = FILTER(data, 3);
CHECK_EQ(result.name(), "FILTER");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 1);
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 0);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[6], 0);
CHECK_EQ(result[7], 0);
a.push_back(0);
a.push_back(0);
a.push_back(1);
a.push_back(1);
data = PRICELIST(a);
result = FILTER(data, 3);
CHECK_EQ(result.name(), "FILTER");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 1);
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 0);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[6], 0);
CHECK_EQ(result[7], 0);
CHECK_EQ(result[8], 0);
CHECK_EQ(result[9], 0);
CHECK_EQ(result[10], 1);
CHECK_EQ(result[11], 0);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
TEST_CASE("test_FILTER_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/FILTER.xml";
Stock stock = sm.getStock("sh000001");
KData kdata = stock.getKData(KQuery(-20));
Indicator x1 = FILTER(CLOSE(kdata) > OPEN(kdata));
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP(x1);
}
Indicator x2;
{
std::ifstream ifs(filename);
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(x2);
}
CHECK_EQ(x2.name(), "FILTER");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/FLOOR.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_FLOOR ) {
TEST_CASE("test_FLOOR") {
Indicator result;
PriceList a;
@ -38,27 +32,26 @@ BOOST_AUTO_TEST_CASE( test_FLOOR ) {
Indicator data = PRICELIST(a);
result = FLOOR(data);
BOOST_CHECK(result.name() == "FLOOR");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == 3);
BOOST_CHECK_CLOSE(result[0], 13, 0.01);
BOOST_CHECK_CLOSE(result[1], 0, 0.01);
BOOST_CHECK_CLOSE(result[2], 1, 0.01);
CHECK_EQ(result.name(), "FLOOR");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], doctest::Approx(13));
CHECK_EQ(result[1], doctest::Approx(0));
CHECK_EQ(result[2], doctest::Approx(1));
result = FLOOR(-11.15);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK_CLOSE(result[0], -12, 0.01);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], doctest::Approx(-12));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_FLOOR_export ) {
TEST_CASE("test_FLOOR_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/FLOOR.xml";
@ -79,16 +72,14 @@ BOOST_AUTO_TEST_CASE( test_FLOOR_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "FLOOR");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "FLOOR");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/CVAL.h>
@ -28,7 +22,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_HHV ) {
TEST_CASE("test_HHV") {
Indicator result;
PriceList a;
@ -40,50 +34,49 @@ BOOST_AUTO_TEST_CASE( test_HHV ) {
/** @arg n = 0 */
result = HHV(data, 0);
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == data[i]);
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], data[i]);
}
/** @arg n = 1 */
result = HHV(data, 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == data[i]);
CHECK_EQ(result[i], data[i]);
}
/** @arg n = 9 */
result = HHV(data, 9);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == data[0]);
BOOST_CHECK(result[1] == data[1]);
BOOST_CHECK(result[7] == data[7]);
BOOST_CHECK(result[8] == data[8]);
BOOST_CHECK(result[9] == data[9]);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], data[0]);
CHECK_EQ(result[1], data[1]);
CHECK_EQ(result[7], data[7]);
CHECK_EQ(result[8], data[8]);
CHECK_EQ(result[9], data[9]);
/** @arg n = 10 */
result = HHV(data, 10);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == data[0]);
BOOST_CHECK(result[1] == data[1]);
BOOST_CHECK(result[8] == data[8]);
BOOST_CHECK(result[9] == data[9]);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], data[0]);
CHECK_EQ(result[1], data[1]);
CHECK_EQ(result[8], data[8]);
CHECK_EQ(result[9], data[9]);
/** ind.size() == 1 */
result = HHV(CVAL(2));
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 2);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 2);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_HHV_export ) {
TEST_CASE("test_HHV_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/HHV.xml";
@ -104,15 +97,13 @@ BOOST_AUTO_TEST_CASE( test_HHV_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -0,0 +1,169 @@
/*
* test_HHVBARS.cpp
*
* Copyright (c) 2019 hikyuu.org
*
* Created on: 201941
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/CVAL.h>
#include <hikyuu/indicator/crt/HHVBARS.h>
#include <hikyuu/indicator/crt/KDATA.h>
#include <hikyuu/indicator/crt/PRICELIST.h>
using namespace hku;
/**
* @defgroup test_indicator_HHVBARS test_indicator_HHVBARS
* @ingroup test_hikyuu_indicator_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_HHVBARS") {
StockManager& sm = StockManager::instance();
Stock stk = sm.getStock("sh000001");
KData k = stk.getKData(-10);
Indicator c = CLOSE(k);
Indicator result;
/** @arg n = 0, 高点顺序上升 */
PriceList a;
for (int i = 0; i < 10; ++i) {
a.push_back(i);
}
Indicator data = PRICELIST(a);
result = HHVBARS(data, 0);
CHECK_EQ(result.name(), "HHVBARS");
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], 0);
}
/** @arg n = 0, 高点降序 */
a.clear();
for (int i = 0; i < 10; ++i) {
a.push_back(10 - i);
}
data = PRICELIST(a);
result = HHVBARS(data, 0);
CHECK_EQ(result.name(), "HHVBARS");
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], i);
}
/** @arg n = 0 顺序随机 */
result = HHVBARS(c, 0);
CHECK_EQ(result.name(), "HHVBARS");
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 0);
CHECK_EQ(result[2], 1);
CHECK_EQ(result[3], 2);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[6], 2);
CHECK_EQ(result[9], 5);
/** @arg n = 1 */
result = HHVBARS(c, 1);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], 0);
}
/** @arg n = 5 */
result = HHVBARS(c, 5);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 0);
CHECK_EQ(result[2], 1);
CHECK_EQ(result[3], 2);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[8], 4);
CHECK_EQ(result[9], 3);
/** @arg n = 10 */
result = HHVBARS(c, 10);
CHECK_EQ(result.name(), "HHVBARS");
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 0);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[6], 2);
CHECK_EQ(result[9], 5);
/** @arg ind.size() == 1 */
result = HHVBARS(CVAL(1));
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
/** @arg n > ind.size() */
result = HHVBARS(c, 20);
CHECK_GT(20, c.size());
CHECK_EQ(result.name(), "HHVBARS");
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 0);
CHECK_EQ(result[2], 1);
CHECK_EQ(result[3], 2);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[6], 2);
CHECK_EQ(result[9], 5);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
TEST_CASE("test_HHVBARS_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/HHVBARS.xml";
Stock stock = sm.getStock("sh000001");
KData kdata = stock.getKData(KQuery(-20));
Indicator x1 = HHVBARS(CLOSE(kdata), 2);
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP(x1);
}
Indicator x2;
{
std::ifstream ifs(filename);
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(x2);
}
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/KDATA.h>
@ -27,9 +20,9 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_IF ) {
TEST_CASE("test_IF") {
KData kdata = getStock("SH600000").getKData(KQuery(-10));
/** @arg 三个参数均为 indicator */
Indicator x = IF(CLOSE() > OPEN(), CVAL(1), CVAL(0));
x.setContext(kdata);
@ -37,9 +30,9 @@ BOOST_AUTO_TEST_CASE( test_IF ) {
Indicator o = OPEN(kdata);
for (int i = 0; i < x.size(); i++) {
if (c[i] > o[i]) {
BOOST_CHECK(x[i] == 1);
CHECK_EQ(x[i], 1);
} else {
BOOST_CHECK(x[i] == 0);
CHECK_EQ(x[i], 0);
}
}
@ -48,9 +41,9 @@ BOOST_AUTO_TEST_CASE( test_IF ) {
x.setContext(kdata);
for (int i = 0; i < x.size(); i++) {
if (c[i] > o[i]) {
BOOST_CHECK(x[i] == 1);
CHECK_EQ(x[i], 1);
} else {
BOOST_CHECK(x[i] == 0);
CHECK_EQ(x[i], 0);
}
}
@ -58,9 +51,9 @@ BOOST_AUTO_TEST_CASE( test_IF ) {
x.setContext(kdata);
for (int i = 0; i < x.size(); i++) {
if (c[i] > o[i]) {
BOOST_CHECK(x[i] == 1);
CHECK_EQ(x[i], 1);
} else {
BOOST_CHECK(x[i] == 0);
CHECK_EQ(x[i], 0);
}
}
@ -69,21 +62,20 @@ BOOST_AUTO_TEST_CASE( test_IF ) {
x.setContext(kdata);
for (int i = 0; i < x.size(); i++) {
if (c[i] > o[i]) {
BOOST_CHECK(x[i] == 1);
CHECK_EQ(x[i], 1);
} else {
BOOST_CHECK(x[i] == 0);
CHECK_EQ(x[i], 0);
}
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_IF_export ) {
TEST_CASE("test_IF_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/IF.xml";
@ -105,14 +97,13 @@ BOOST_AUTO_TEST_CASE( test_IF_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -0,0 +1,221 @@
/*
* test_IKData.cpp
*
* Created on: 2013-2-12
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/KDATA.h>
using namespace hku;
/**
* @defgroup test_indicator_IKData test_indicator_IKData
* @ingroup test_hikyuu_indicator_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_IKData") {
StockManager& sm = StockManager::instance();
Stock stock = sm.getStock("sh000001");
KData kdata;
/** @arg Indicator为空 */
Indicator ki, open, high, low, close, amount, count;
CHECK_EQ(open.size(), 0);
CHECK_EQ(open.empty(), true);
/** @arg 对应的KData为空 */
ki = KDATA(kdata);
CHECK_EQ(ki.size(), 0);
CHECK_EQ(ki.empty(), true);
open = OPEN(kdata);
CHECK_EQ(open.size(), 0);
CHECK_EQ(open.empty(), true);
high = HIGH(kdata);
CHECK_EQ(high.size(), 0);
CHECK_EQ(high.empty(), true);
low = LOW(kdata);
CHECK_EQ(low.size(), 0);
CHECK_EQ(low.empty(), true);
close = CLOSE(kdata);
CHECK_EQ(close.size(), 0);
CHECK_EQ(close.empty(), true);
amount = AMO(kdata);
CHECK_EQ(amount.size(), 0);
CHECK_EQ(amount.empty(), true);
count = VOL(kdata);
CHECK_EQ(count.size(), 0);
CHECK_EQ(count.empty(), true);
/** @arg 非空的KData */
KQuery query(10);
kdata = stock.getKData(query);
size_t total = kdata.size();
ki = KDATA(kdata);
CHECK_EQ(ki.size(), kdata.size());
for (size_t i = 0; i < total; ++i) {
CHECK_EQ(ki.get(i, 0), kdata[i].openPrice);
CHECK_EQ(ki.get(i, 1), kdata[i].highPrice);
CHECK_EQ(ki.get(i, 2), kdata[i].lowPrice);
CHECK_EQ(ki.get(i, 3), kdata[i].closePrice);
CHECK_EQ(ki.get(i, 4), kdata[i].transAmount);
CHECK_EQ(ki.get(i, 5), kdata[i].transCount);
}
open = OPEN(kdata);
CHECK_EQ(open.size(), kdata.size());
for (size_t i = 0; i < total; ++i) {
CHECK_EQ(open[i], kdata[i].openPrice);
}
high = HIGH(kdata);
CHECK_EQ(high.size(), kdata.size());
for (size_t i = 0; i < total; ++i) {
CHECK_EQ(high[i], kdata[i].highPrice);
}
low = LOW(kdata);
CHECK_EQ(low.size(), kdata.size());
for (size_t i = 0; i < total; ++i) {
CHECK_EQ(low[i], kdata[i].lowPrice);
}
close = CLOSE(kdata);
CHECK_EQ(close.size(), kdata.size());
for (size_t i = 0; i < total; ++i) {
CHECK_EQ(close[i], kdata[i].closePrice);
}
amount = AMO(kdata);
CHECK_EQ(amount.size(), kdata.size());
for (size_t i = 0; i < total; ++i) {
CHECK_EQ(amount[i], kdata[i].transAmount);
}
count = VOL(kdata);
CHECK_EQ(count.size(), kdata.size());
for (size_t i = 0; i < total; ++i) {
CHECK_EQ(count[i], kdata[i].transCount);
}
}
/** @par 检测点 */
TEST_CASE("test_IKData_setContext") {
StockManager& sm = StockManager::instance();
Stock stock = sm.getStock("sh000001");
KQuery query(10);
KData kdata = stock.getKData(query);
size_t total = kdata.size();
Indicator ki, open, high, low, close, amount, count;
ki = KDATA();
ki.setContext(stock, query);
CHECK_EQ(ki.size(), kdata.size());
for (size_t i = 0; i < total; ++i) {
CHECK_EQ(ki.get(i, 0), kdata[i].openPrice);
CHECK_EQ(ki.get(i, 1), kdata[i].highPrice);
CHECK_EQ(ki.get(i, 2), kdata[i].lowPrice);
CHECK_EQ(ki.get(i, 3), kdata[i].closePrice);
CHECK_EQ(ki.get(i, 4), kdata[i].transAmount);
CHECK_EQ(ki.get(i, 5), kdata[i].transCount);
}
open = OPEN();
open.setContext(stock, query);
CHECK_EQ(open.size(), kdata.size());
for (size_t i = 0; i < total; ++i) {
CHECK_EQ(open[i], kdata[i].openPrice);
}
high = HIGH();
high.setContext(stock, query);
CHECK_EQ(high.size(), kdata.size());
for (size_t i = 0; i < total; ++i) {
CHECK_EQ(high[i], kdata[i].highPrice);
}
low = LOW();
low.setContext(stock, query);
CHECK_EQ(low.size(), kdata.size());
for (size_t i = 0; i < total; ++i) {
CHECK_EQ(low[i], kdata[i].lowPrice);
}
close = CLOSE();
close.setContext(stock, query);
CHECK_EQ(close.size(), kdata.size());
for (size_t i = 0; i < total; ++i) {
CHECK_EQ(close[i], kdata[i].closePrice);
}
amount = AMO();
amount.setContext(stock, query);
CHECK_EQ(amount.size(), kdata.size());
for (size_t i = 0; i < total; ++i) {
CHECK_EQ(amount[i], kdata[i].transAmount);
}
count = VOL();
count.setContext(stock, query);
CHECK_EQ(count.size(), kdata.size());
for (size_t i = 0; i < total; ++i) {
CHECK_EQ(count[i], kdata[i].transCount);
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
TEST_CASE("test_KDATA_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/IKDATA.xml";
Stock stock = sm.getStock("sh000001");
KData kdata = stock.getKData(KQuery(-20));
Indicator ma1 = KDATA(kdata);
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP(ma1);
}
Indicator ma2;
{
std::ifstream ifs(filename);
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(ma2);
}
CHECK_EQ(ma1.size(), ma2.size());
CHECK_EQ(ma1.discard(), ma2.discard());
CHECK_EQ(ma1.getResultNumber(), ma2.getResultNumber());
for (size_t i = 0; i < ma1.size(); ++i) {
CHECK_EQ(ma1.get(i, 0), doctest::Approx(ma2.get(i, 0)));
CHECK_EQ(ma1.get(i, 1), doctest::Approx(ma2.get(i, 1)));
CHECK_EQ(ma1.get(i, 2), doctest::Approx(ma2.get(i, 2)));
CHECK_EQ(ma1.get(i, 3), doctest::Approx(ma2.get(i, 3)));
CHECK_EQ(ma1.get(i, 4), doctest::Approx(ma2.get(i, 4)));
CHECK_EQ(ma1.get(i, 5), doctest::Approx(ma2.get(i, 5)));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -4,14 +4,7 @@
* Created on: 2019-4-18
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/INTPART.h>
@ -27,7 +20,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_INTPART ) {
TEST_CASE("test_INTPART") {
Indicator result;
PriceList a;
@ -38,27 +31,26 @@ BOOST_AUTO_TEST_CASE( test_INTPART ) {
Indicator data = PRICELIST(a);
result = INTPART(data);
BOOST_CHECK(result.name() == "INTPART");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == 3);
BOOST_CHECK_CLOSE(result[0], 13, 0.01);
BOOST_CHECK_CLOSE(result[1], 0, 0.01);
BOOST_CHECK_CLOSE(result[2], 1, 0.01);
CHECK_EQ(result.name(), "INTPART");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], doctest::Approx(13));
CHECK_EQ(result[1], doctest::Approx(0));
CHECK_EQ(result[2], doctest::Approx(1));
result = INTPART(-11.15);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK_CLOSE(result[0], -11, 0.01);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], doctest::Approx(-11));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_INTPART_export ) {
TEST_CASE("test_INTPART_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/INTPART.xml";
@ -79,16 +71,14 @@ BOOST_AUTO_TEST_CASE( test_INTPART_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "INTPART");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "INTPART");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <hikyuu/indicator/Indicator.h>
#include <hikyuu/indicator/crt/PRICELIST.h>
#include <hikyuu/indicator/crt/KDATA.h>
@ -26,30 +20,30 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_operator_add ) {
TEST_CASE("test_operator_add") {
/** @arg 正常相加*/
PriceList d1, d2;
for (size_t i = 0; i < 10; ++i) {
d1.push_back(i);
d2.push_back(i+1);
d2.push_back(i + 1);
}
Indicator data1 = PRICELIST(d1);
Indicator data2 = PRICELIST(d2);
Indicator result = data1 + data2;
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == i + i + 1);
CHECK_EQ(result[i], i + i + 1);
}
/** @arg 两个待加的ind的size不同其中一个为0 */
Indicator data3;
result = data1 + data3;
BOOST_CHECK(result.empty());
BOOST_CHECK(result.size() == 0);
CHECK_UNARY(result.empty());
CHECK_EQ(result.size(), 0);
/** @arg 两个待加的ind的size不同其中一个为0 */
PriceList d3;
@ -58,16 +52,16 @@ BOOST_AUTO_TEST_CASE( test_operator_add ) {
}
data3 = PRICELIST(d3);
result = data1 + data3;
BOOST_CHECK(data1.size() == 10);
BOOST_CHECK(data3.size() == 20);
BOOST_CHECK(result.empty() == false);
BOOST_CHECK(result.size() == 20);
BOOST_CHECK(result.discard() == 10);
CHECK_EQ(data1.size(), 10);
CHECK_EQ(data3.size(), 20);
CHECK_EQ(result.empty(), false);
CHECK_EQ(result.size(), 20);
CHECK_EQ(result.discard(), 10);
for (size_t i = 0; i < result.discard(); ++i) {
BOOST_CHECK(std::isnan(result[i]));
CHECK_UNARY(std::isnan(result[i]));
}
for (size_t i = result.discard(); i < 20; ++i) {
BOOST_CHECK(result[i] == i + i - 10);
CHECK_EQ(result[i], i + i - 10);
}
/** @arg 两个待加的ind的size相同但result_number不同 */
@ -76,39 +70,39 @@ BOOST_AUTO_TEST_CASE( test_operator_add ) {
KQuery query(0, 10);
KData kdata = stock.getKData(query);
Indicator k = KDATA(kdata);
BOOST_CHECK(k.size() == data1.size());
CHECK_EQ(k.size(), data1.size());
result = k + data1;
BOOST_CHECK(result.size() == k.size());
BOOST_CHECK(result.getResultNumber() == 1);
CHECK_EQ(result.size(), k.size());
CHECK_EQ(result.getResultNumber(), 1);
for (size_t i = 0; i < result.size(); ++i) {
BOOST_CHECK(result[i] == (k[i] + data1[i]));
CHECK_EQ(result[i], (k[i] + data1[i]));
}
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_operator_reduce ) {
TEST_CASE("test_operator_reduce") {
/** @arg 正常相减*/
PriceList d1, d2;
for (size_t i = 0; i < 10; ++i) {
d1.push_back(i);
d2.push_back(i+1);
d2.push_back(i + 1);
}
Indicator data1 = PRICELIST(d1);
Indicator data2 = PRICELIST(d2);
Indicator result = data1 - data2;
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == data1[i] - data2[i]);
CHECK_EQ(result[i], data1[i] - data2[i]);
}
/** @arg 两个待减的ind的size不同 */
Indicator data3;
result = data1 - data3;
BOOST_CHECK(result.empty());
BOOST_CHECK(result.size() == 0);
CHECK_UNARY(result.empty());
CHECK_EQ(result.size(), 0);
/** @arg 两个待减的ind的size相同但result_number不同 */
StockManager& sm = StockManager::instance();
@ -116,39 +110,38 @@ BOOST_AUTO_TEST_CASE( test_operator_reduce ) {
KQuery query(0, 10);
KData kdata = stock.getKData(query);
Indicator k = KDATA(kdata);
BOOST_CHECK(k.size() == data1.size());
CHECK_EQ(k.size(), data1.size());
result = k - data1;
BOOST_CHECK(result.size() == k.size());
CHECK_EQ(result.size(), k.size());
for (size_t i = 0; i < result.size(); ++i) {
BOOST_CHECK(result[i] == (k[i] - data1[i]));
CHECK_EQ(result[i], (k[i] - data1[i]));
}
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_operator_multi ) {
TEST_CASE("test_operator_multi") {
/** @arg 正常相乘*/
PriceList d1, d2;
for (size_t i = 0; i < 10; ++i) {
d1.push_back(i);
d2.push_back(i+1);
d2.push_back(i + 1);
}
Indicator data1 = PRICELIST(d1);
Indicator data2 = PRICELIST(d2);
Indicator result = data1 * data2;
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == data1[i] * data2[i]);
CHECK_EQ(result[i], data1[i] * data2[i]);
}
/** @arg 两个待乘的ind的size不同 */
Indicator data3;
result = data1 * data3;
BOOST_CHECK(result.empty());
BOOST_CHECK(result.size() == 0);
CHECK_UNARY(result.empty());
CHECK_EQ(result.size(), 0);
/** @arg 两个待乘的ind的size相同但result_number不同 */
StockManager& sm = StockManager::instance();
@ -156,43 +149,42 @@ BOOST_AUTO_TEST_CASE( test_operator_multi ) {
KQuery query(0, 10);
KData kdata = stock.getKData(query);
Indicator k = KDATA(kdata);
BOOST_CHECK(k.size() == data1.size());
CHECK_EQ(k.size(), data1.size());
result = k * data1;
BOOST_CHECK(result.size() == k.size());
CHECK_EQ(result.size(), k.size());
for (size_t i = 0; i < result.size(); ++i) {
BOOST_CHECK(result[i] == (k[i] * data1[i]));
CHECK_EQ(result[i], (k[i] * data1[i]));
}
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_operator_division ) {
TEST_CASE("test_operator_division") {
/** @arg 正常相除*/
PriceList d1, d2;
for (size_t i = 0; i < 10; ++i) {
d1.push_back(i);
d2.push_back(i+1);
d2.push_back(i + 1);
}
Indicator data1 = PRICELIST(d1);
Indicator data2 = PRICELIST(d2);
Indicator result = data2 / data1;
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < 10; ++i) {
if (data1[i] == 0.0) {
BOOST_CHECK(std::isnan(result[i]));
CHECK_UNARY(std::isnan(result[i]));
} else {
BOOST_CHECK(result[i] == data2[i] / data1[i]);
CHECK_EQ(result[i], data2[i] / data1[i]);
}
}
/** @arg 两个待除的ind的size不同 */
Indicator data3;
result = data1 / data3;
BOOST_CHECK(result.empty());
BOOST_CHECK(result.size() == 0);
CHECK_UNARY(result.empty());
CHECK_EQ(result.size(), 0);
/** @arg 两个待除的ind的size相同但result_number不同 */
StockManager& sm = StockManager::instance();
@ -200,49 +192,49 @@ BOOST_AUTO_TEST_CASE( test_operator_division ) {
KQuery query(0, 10);
KData kdata = stock.getKData(query);
Indicator k = KDATA(kdata);
BOOST_CHECK(k.size() == data1.size());
CHECK_EQ(k.size(), data1.size());
result = k / data1;
BOOST_CHECK(result.size() == k.size());
CHECK_EQ(result.size(), k.size());
for (size_t i = 0; i < result.size(); ++i) {
if (data1[i] == 0.0) {
BOOST_CHECK(std::isnan(result[i]));
CHECK_UNARY(std::isnan(result[i]));
} else {
BOOST_CHECK(result[i] == (k[i] / data1[i]));
CHECK_EQ(result[i], (k[i] / data1[i]));
}
}
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_operator_mod ) {
TEST_CASE("test_operator_mod") {
/** @arg 正常取模*/
PriceList d1, d2;
for (size_t i = 0; i < 10; ++i) {
d1.push_back(i);
d2.push_back(i+2);
d2.push_back(i + 2);
}
Indicator data1 = PRICELIST(d1);
Indicator data2 = PRICELIST(d2);
Indicator result = data2 % data1;
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(std::isnan(result[0]));
BOOST_CHECK(result[1] == 0);
BOOST_CHECK(result[2] == 0);
BOOST_CHECK(result[3] == 2);
BOOST_CHECK(result[4] == 2);
BOOST_CHECK(result[5] == 2);
BOOST_CHECK(result[6] == 2);
BOOST_CHECK(result[7] == 2);
BOOST_CHECK(result[8] == 2);
BOOST_CHECK(result[9] == 2);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_UNARY(std::isnan(result[0]));
CHECK_EQ(result[1], 0);
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 2);
CHECK_EQ(result[4], 2);
CHECK_EQ(result[5], 2);
CHECK_EQ(result[6], 2);
CHECK_EQ(result[7], 2);
CHECK_EQ(result[8], 2);
CHECK_EQ(result[9], 2);
/** @arg 两个待除的ind的size不同 */
Indicator data3;
result = data1 % data3;
BOOST_CHECK(result.empty());
BOOST_CHECK(result.size() == 0);
CHECK_UNARY(result.empty());
CHECK_EQ(result.size(), 0);
/** @arg 两个待除的ind的size相同但result_number不同 */
StockManager& sm = StockManager::instance();
@ -250,23 +242,23 @@ BOOST_AUTO_TEST_CASE( test_operator_mod ) {
KQuery query(0, 10);
KData kdata = stock.getKData(query);
Indicator k = KDATA(kdata);
BOOST_CHECK(k.size() == data1.size());
CHECK_EQ(k.size(), data1.size());
result = k % data1;
BOOST_CHECK(result.size() == k.size());
BOOST_CHECK(std::isnan(result[0]));
BOOST_CHECK(result[1] == 0);
BOOST_CHECK(result[2] == 1);
BOOST_CHECK(result[3] == 1);
BOOST_CHECK(result[4] == 3);
BOOST_CHECK(result[5] == 1);
BOOST_CHECK(result[6] == 3);
BOOST_CHECK(result[7] == 6);
BOOST_CHECK(result[8] == 2);
BOOST_CHECK(result[9] == 8);
CHECK_EQ(result.size(), k.size());
CHECK_UNARY(std::isnan(result[0]));
CHECK_EQ(result[1], 0);
CHECK_EQ(result[2], 1);
CHECK_EQ(result[3], 1);
CHECK_EQ(result[4], 3);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[6], 3);
CHECK_EQ(result[7], 6);
CHECK_EQ(result[8], 2);
CHECK_EQ(result[9], 8);
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_operator_eq ) {
TEST_CASE("test_operator_eq") {
/** @arg 正常相等*/
PriceList d1, d2;
for (size_t i = 0; i < 10; ++i) {
@ -277,18 +269,18 @@ BOOST_AUTO_TEST_CASE( test_operator_eq ) {
Indicator data1 = PRICELIST(d1);
Indicator data2 = PRICELIST(d2);
Indicator result = (data2 == data1);
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == true);
CHECK_EQ(result[i], true);
}
/** @arg 两个ind的size不同 */
Indicator data3;
result = (data1 == data3);
BOOST_CHECK(result.empty());
BOOST_CHECK(result.size() == 0);
CHECK_UNARY(result.empty());
CHECK_EQ(result.size(), 0);
/** @arg 两个ind的size相同但result_number不同 */
StockManager& sm = StockManager::instance();
@ -296,16 +288,16 @@ BOOST_AUTO_TEST_CASE( test_operator_eq ) {
KQuery query(0, 10);
KData kdata = stock.getKData(query);
Indicator k = KDATA(kdata);
BOOST_CHECK(k.size() == data1.size());
CHECK_EQ(k.size(), data1.size());
result = (k == data1);
BOOST_CHECK(result.size() == k.size());
CHECK_EQ(result.size(), k.size());
for (size_t i = 0; i < result.size(); ++i) {
BOOST_CHECK(result[i] == false);
CHECK_EQ(result[i], false);
}
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_operator_ne ) {
TEST_CASE("test_operator_ne") {
/** @arg 正常不相等 */
PriceList d1, d2;
for (size_t i = 0; i < 10; ++i) {
@ -316,18 +308,18 @@ BOOST_AUTO_TEST_CASE( test_operator_ne ) {
Indicator data1 = PRICELIST(d1);
Indicator data2 = PRICELIST(d2);
Indicator result = (data2 != data1);
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == false);
CHECK_EQ(result[i], false);
}
/** @arg 两个ind的size不同 */
Indicator data3;
result = (data1 != data3);
BOOST_CHECK(result.empty());
BOOST_CHECK(result.size() == 0);
CHECK_UNARY(result.empty());
CHECK_EQ(result.size(), 0);
/** @arg 两个ind的size相同但result_number不同 */
StockManager& sm = StockManager::instance();
@ -335,21 +327,21 @@ BOOST_AUTO_TEST_CASE( test_operator_ne ) {
KQuery query(0, 10);
KData kdata = stock.getKData(query);
Indicator k = KDATA(kdata);
BOOST_CHECK(k.size() == data1.size());
CHECK_EQ(k.size(), data1.size());
result = (k != data1);
BOOST_CHECK(result.size() == k.size());
CHECK_EQ(result.size(), k.size());
for (size_t i = 0; i < result.size(); ++i) {
BOOST_CHECK(result[i] == true);
CHECK_EQ(result[i], true);
}
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_operator_gt ) {
TEST_CASE("test_operator_gt") {
PriceList d1, d2, d3;
for (size_t i = 0; i < 10; ++i) {
d1.push_back(i);
d2.push_back(i);
d3.push_back(i+1);
d3.push_back(i + 1);
}
Indicator data1 = PRICELIST(d1);
@ -358,30 +350,30 @@ BOOST_AUTO_TEST_CASE( test_operator_gt ) {
/** @arg ind1 > ind2*/
Indicator result = (data3 > data1);
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 1.0);
CHECK_EQ(result[i], 1.0);
}
/** @arg ind1 < ind2 */
result = (data1 > data3);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 0.0);
CHECK_EQ(result[i], 0.0);
}
/** @arg ind1 == ind2 */
result = (data1 > data2);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 0.0);
CHECK_EQ(result[i], 0.0);
}
/** @arg 两个ind的size不同 */
Indicator data4;
result = data1 > data4;
BOOST_CHECK(result.empty());
BOOST_CHECK(result.size() == 0);
CHECK_UNARY(result.empty());
CHECK_EQ(result.size(), 0);
/** @arg 两个ind的size相同但result_number不同 */
StockManager& sm = StockManager::instance();
@ -389,21 +381,21 @@ BOOST_AUTO_TEST_CASE( test_operator_gt ) {
KQuery query(0, 10);
KData kdata = stock.getKData(query);
Indicator k = KDATA(kdata);
BOOST_CHECK(k.size() == data1.size());
CHECK_EQ(k.size(), data1.size());
result = (k > data1);
BOOST_CHECK(result.size() == k.size());
CHECK_EQ(result.size(), k.size());
for (size_t i = 0; i < result.size(); ++i) {
BOOST_CHECK(result[i] == 1.0);
CHECK_EQ(result[i], 1.0);
}
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_operator_ge ) {
TEST_CASE("test_operator_ge") {
PriceList d1, d2, d3;
for (size_t i = 0; i < 10; ++i) {
d1.push_back(i);
d2.push_back(i);
d3.push_back(i+1);
d3.push_back(i + 1);
}
Indicator data1 = PRICELIST(d1);
@ -412,30 +404,30 @@ BOOST_AUTO_TEST_CASE( test_operator_ge ) {
/** @arg ind1 > ind2*/
Indicator result = (data3 >= data1);
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 1.0);
CHECK_EQ(result[i], 1.0);
}
/** @arg ind1 < ind2 */
result = (data1 >= data3);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 0.0);
CHECK_EQ(result[i], 0.0);
}
/** @arg ind1 == ind2 */
result = (data1 >= data2);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 1.0);
CHECK_EQ(result[i], 1.0);
}
/** @arg 两个ind的size不同 */
Indicator data4;
result = data1 >= data4;
BOOST_CHECK(result.empty());
BOOST_CHECK(result.size() == 0);
CHECK_UNARY(result.empty());
CHECK_EQ(result.size(), 0);
/** @arg 两个ind的size相同但result_number不同 */
StockManager& sm = StockManager::instance();
@ -443,21 +435,21 @@ BOOST_AUTO_TEST_CASE( test_operator_ge ) {
KQuery query(0, 10);
KData kdata = stock.getKData(query);
Indicator k = KDATA(kdata);
BOOST_CHECK(k.size() == data1.size());
CHECK_EQ(k.size(), data1.size());
result = (k >= data1);
BOOST_CHECK(result.size() == k.size());
CHECK_EQ(result.size(), k.size());
for (size_t i = 0; i < result.size(); ++i) {
BOOST_CHECK(result[i] == 1.0);
CHECK_EQ(result[i], 1.0);
}
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_operator_lt ) {
TEST_CASE("test_operator_lt") {
PriceList d1, d2, d3;
for (size_t i = 0; i < 10; ++i) {
d1.push_back(i);
d2.push_back(i);
d3.push_back(i+1);
d3.push_back(i + 1);
}
Indicator data1 = PRICELIST(d1);
@ -466,30 +458,30 @@ BOOST_AUTO_TEST_CASE( test_operator_lt ) {
/** @arg ind1 > ind2*/
Indicator result = (data3 < data1);
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 0.0);
CHECK_EQ(result[i], 0.0);
}
/** @arg ind1 < ind2 */
result = (data1 < data3);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 1.0);
CHECK_EQ(result[i], 1.0);
}
/** @arg ind1 == ind2 */
result = (data1 < data2);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 0.0);
CHECK_EQ(result[i], 0.0);
}
/** @arg 两个ind的size不同 */
Indicator data4;
result = data1 < data4;
BOOST_CHECK(result.empty());
BOOST_CHECK(result.size() == 0);
CHECK_UNARY(result.empty());
CHECK_EQ(result.size(), 0);
/** @arg 两个ind的size相同但result_number不同 */
StockManager& sm = StockManager::instance();
@ -497,21 +489,21 @@ BOOST_AUTO_TEST_CASE( test_operator_lt ) {
KQuery query(0, 10);
KData kdata = stock.getKData(query);
Indicator k = KDATA(kdata);
BOOST_CHECK(k.size() == data1.size());
CHECK_EQ(k.size(), data1.size());
result = (k < data1);
BOOST_CHECK(result.size() == k.size());
CHECK_EQ(result.size(), k.size());
for (size_t i = 0; i < result.size(); ++i) {
BOOST_CHECK(result[i] == 0.0);
CHECK_EQ(result[i], 0.0);
}
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_operator_le ) {
TEST_CASE("test_operator_le") {
PriceList d1, d2, d3;
for (size_t i = 0; i < 10; ++i) {
d1.push_back(i);
d2.push_back(i);
d3.push_back(i+1);
d3.push_back(i + 1);
}
Indicator data1 = PRICELIST(d1);
@ -520,30 +512,30 @@ BOOST_AUTO_TEST_CASE( test_operator_le ) {
/** @arg ind1 > ind2*/
Indicator result = (data3 <= data1);
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 0.0);
CHECK_EQ(result[i], 0.0);
}
/** @arg ind1 < ind2 */
result = (data1 <= data3);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 1.0);
CHECK_EQ(result[i], 1.0);
}
/** @arg ind1 == ind2 */
result = (data1 <= data2);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 1.0);
CHECK_EQ(result[i], 1.0);
}
/** @arg 两个ind的size不同 */
Indicator data4;
result = data1 <= data4;
BOOST_CHECK(result.empty());
BOOST_CHECK(result.size() == 0);
CHECK_UNARY(result.empty());
CHECK_EQ(result.size(), 0);
/** @arg 两个ind的size相同但result_number不同 */
StockManager& sm = StockManager::instance();
@ -551,17 +543,16 @@ BOOST_AUTO_TEST_CASE( test_operator_le ) {
KQuery query(0, 10);
KData kdata = stock.getKData(query);
Indicator k = KDATA(kdata);
BOOST_CHECK(k.size() == data1.size());
CHECK_EQ(k.size(), data1.size());
result = (k <= data1);
BOOST_CHECK(result.size() == k.size());
CHECK_EQ(result.size(), k.size());
for (size_t i = 0; i < result.size(); ++i) {
BOOST_CHECK(result[i] == 0.0);
CHECK_EQ(result[i], 0.0);
}
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_getResult_getResultAsPriceList ) {
TEST_CASE("test_getResult_getResultAsPriceList") {
StockManager& sm = StockManager::instance();
Stock stock = sm.getStock("sh600000");
KQuery query;
@ -573,36 +564,35 @@ BOOST_AUTO_TEST_CASE( test_getResult_getResultAsPriceList ) {
ikdata = KDATA(kdata);
result1 = ikdata.getResult(0);
result2 = ikdata.getResultAsPriceList(0);
BOOST_CHECK(result1.size() == 0);
BOOST_CHECK(result2.size() == 0);
CHECK_EQ(result1.size(), 0);
CHECK_EQ(result2.size(), 0);
/** @arg result_num参数非法 */
query = KQuery(0, 10);
kdata = stock.getKData(query);
ikdata = KDATA(kdata);
BOOST_CHECK(ikdata.size() == 10);
CHECK_EQ(ikdata.size(), 10);
result1 = ikdata.getResult(6);
result2 = ikdata.getResultAsPriceList(6);
BOOST_CHECK(result1.size() == 0);
BOOST_CHECK(result2.size() == 0);
CHECK_EQ(result1.size(), 0);
CHECK_EQ(result2.size(), 0);
/** @arg 正常获取 */
result1 = ikdata.getResult(0);
result2 = ikdata.getResultAsPriceList(1);
BOOST_CHECK(result1.size() == 10);
BOOST_CHECK(result2.size() == 10);
BOOST_CHECK(result1[0] == 29.5);
BOOST_CHECK(std::fabs(result1[1] - 27.58) < 0.0001);
BOOST_CHECK(result1[9] == 26.45);
CHECK_EQ(result1.size(), 10);
CHECK_EQ(result2.size(), 10);
CHECK_EQ(result1[0], 29.5);
CHECK_LT(std::fabs(result1[1] - 27.58), 0.0001);
CHECK_EQ(result1[9], 26.45);
BOOST_CHECK(result2[0] == 29.8);
BOOST_CHECK(result2[1] == 28.38);
BOOST_CHECK(result2[9] == 26.55);
CHECK_EQ(result2[0], 29.8);
CHECK_EQ(result2[1], 28.38);
CHECK_EQ(result2[9], 26.55);
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_LOGIC_AND ) {
TEST_CASE("test_LOGIC_AND") {
PriceList d1, d2, d3;
for (size_t i = 0; i < 10; ++i) {
d1.push_back(0);
@ -616,11 +606,11 @@ BOOST_AUTO_TEST_CASE( test_LOGIC_AND ) {
/** @arg ind1为全0 ind2为全1 */
Indicator result = data1 & data2;
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 0.0);
CHECK_EQ(result[i], 0.0);
}
/** @arg ind为全0 val为1 */
@ -634,33 +624,32 @@ BOOST_AUTO_TEST_CASE( test_LOGIC_AND ) {
/** @arg ind1为全0 ind2为从0开始的整数 */
result = data1 & data3;
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 0.0);
CHECK_EQ(result[i], 0.0);
}
/** @arg ind1为全1 ind2为从0开始的整数 */
result = data2 & data3;
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 0.0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0.0);
for (size_t i = 1; i < 10; ++i) {
BOOST_CHECK(result[i] == 1.0);
CHECK_EQ(result[i], 1.0);
}
/** @arg 两个ind的size不同 */
Indicator data4;
result = data1 & data4;
BOOST_CHECK(result.empty());
BOOST_CHECK(result.size() == 0);
CHECK_UNARY(result.empty());
CHECK_EQ(result.size(), 0);
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_LOGIC_OR ) {
TEST_CASE("test_LOGIC_OR") {
PriceList d1, d2, d3;
for (size_t i = 0; i < 10; ++i) {
d1.push_back(0);
@ -674,37 +663,37 @@ BOOST_AUTO_TEST_CASE( test_LOGIC_OR ) {
/** @arg ind1为全0 ind2为全1 */
Indicator result = data1 | data2;
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 1.0);
CHECK_EQ(result[i], 1.0);
}
/** @arg ind1为全0 ind2为从0开始的整数 */
result = data1 | data3;
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 0.0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0.0);
for (size_t i = 1; i < 10; ++i) {
BOOST_CHECK(result[i] == 1.0);
CHECK_EQ(result[i], 1.0);
}
/** @arg ind1为全1 ind2为从0开始的整数 */
result = data2 | data3;
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.getResultNumber() == 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.getResultNumber(), 1);
CHECK_EQ(result.discard(), 0);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == 1.0);
CHECK_EQ(result[i], 1.0);
}
/** @arg 两个ind的size不同 */
Indicator data4;
result = data1 | data4;
BOOST_CHECK(result.empty());
BOOST_CHECK(result.size() == 0);
CHECK_UNARY(result.empty());
CHECK_EQ(result.size(), 0);
}
/** @} */

View File

@ -0,0 +1,159 @@
/*
* test_LAST.cpp
*
* Created on: 2019-4-28
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/LAST.h>
#include <hikyuu/indicator/crt/KDATA.h>
#include <hikyuu/indicator/crt/PRICELIST.h>
using namespace hku;
/**
* @defgroup test_indicator_LAST test_indicator_LAST
* @ingroup test_hikyuu_indicator_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_LAST") {
Indicator result;
PriceList a;
a.push_back(0); // 0
a.push_back(1); // 1
a.push_back(2); // 2
a.push_back(3); // 3
a.push_back(4); // 4
a.push_back(0); // 5
a.push_back(0); // 6
a.push_back(7); // 7
a.push_back(8); // 8
a.push_back(9); // 9
a.push_back(10); // 10
Indicator data = PRICELIST(a);
/** @arg m=0, n=0 */
result = LAST(data, 0, 0);
CHECK_EQ(result.name(), "LAST");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 1);
CHECK_EQ(result[2], 1);
CHECK_EQ(result[3], 1);
CHECK_EQ(result[4], 1);
CHECK_EQ(result[5], 0);
CHECK_EQ(result[6], 0);
CHECK_EQ(result[7], 1);
CHECK_EQ(result[8], 1);
CHECK_EQ(result[9], 1);
CHECK_EQ(result[10], 1);
/** @arg m=0, n=5 */
result = LAST(data, 0, 5);
CHECK_EQ(result.name(), "LAST");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 5);
CHECK_EQ(result[5], 0);
CHECK_EQ(result[6], 0);
CHECK_EQ(result[7], 0);
CHECK_EQ(result[8], 0);
CHECK_EQ(result[9], 0);
CHECK_EQ(result[10], 0);
/** @arg m=6,n=3*/
result = LAST(data, 6, 3);
CHECK_EQ(result.name(), "LAST");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 6);
CHECK_EQ(result[6], 0);
CHECK_EQ(result[7], 1);
CHECK_EQ(result[8], 0);
CHECK_EQ(result[9], 0);
CHECK_EQ(result[10], 0);
/** @arg m=3,n=6*/
result = LAST(data, 6, 3);
CHECK_EQ(result.name(), "LAST");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 6);
CHECK_EQ(result[6], 0);
CHECK_EQ(result[7], 1);
CHECK_EQ(result[8], 0);
CHECK_EQ(result[9], 0);
CHECK_EQ(result[10], 0);
/** @arg m=3,n=2*/
result = LAST(data, 3, 2);
CHECK_EQ(result.name(), "LAST");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 3);
CHECK_EQ(result[3], 0);
CHECK_EQ(result[4], 1);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[6], 1);
CHECK_EQ(result[7], 0);
CHECK_EQ(result[8], 0);
CHECK_EQ(result[9], 0);
CHECK_EQ(result[10], 1);
/** @arg m=3,n=3*/
result = LAST(data, 3, 3);
CHECK_EQ(result.name(), "LAST");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 3);
CHECK_EQ(result[3], 0);
CHECK_EQ(result[4], 1);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[6], 1);
CHECK_EQ(result[7], 1);
CHECK_EQ(result[8], 0);
CHECK_EQ(result[9], 0);
CHECK_EQ(result[10], 1);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
TEST_CASE("test_LAST_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/LAST.xml";
Stock stock = sm.getStock("sh000001");
KData kdata = stock.getKData(KQuery(-20));
Indicator x1 = LAST(CLOSE(kdata) > OPEN(kdata));
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP(x1);
}
Indicator x2;
{
std::ifstream ifs(filename);
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(x2);
}
CHECK_EQ(x2.name(), "LAST");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/LIUTONGPAN.h>
@ -26,36 +19,34 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_LIUTONGPAN ) {
TEST_CASE("test_LIUTONGPAN") {
StockManager& sm = StockManager::instance();
Stock stk = getStock("SH600004");
KQuery query = KQueryByDate(Datetime(200301010000), Datetime(200708250000));
KData k = stk.getKData(query);
Indicator liutong = LIUTONGPAN(k);
BOOST_CHECK(liutong.size() == k.size());
CHECK_EQ(liutong.size(), k.size());
size_t total = k.size();
for (int i = 0; i < total; i++) {
if (k[i].datetime < Datetime(200512200000)) {
BOOST_CHECK(liutong[i] == 40000);
} else if (k[i].datetime >= Datetime(200512200000)
&& k[i].datetime < Datetime(200612200000)) {
BOOST_CHECK(liutong[i] == 47600);
CHECK_EQ(liutong[i], 40000);
} else if (k[i].datetime >= Datetime(200512200000) && k[i].datetime < Datetime(200612200000)) {
CHECK_EQ(liutong[i], 47600);
} else {
BOOST_CHECK(liutong[i] == 49696);
CHECK_EQ(liutong[i], 49696);
}
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_LIUTONGPAN_export ) {
TEST_CASE("test_LIUTONGPAN_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/LIUTONGPAN.xml";
@ -77,15 +68,14 @@ BOOST_AUTO_TEST_CASE( test_LIUTONGPAN_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "LIUTONGPAN");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "LIUTONGPAN");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/LLV.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_LLV ) {
TEST_CASE("test_LLV") {
Indicator result;
PriceList a;
@ -39,42 +33,41 @@ BOOST_AUTO_TEST_CASE( test_LLV ) {
/** @arg n = 0 */
result = LLV(data, 0);
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == data[0]);
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], data[0]);
}
/** @arg n = 1 */
result = LLV(data, 1);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == data[i]);
CHECK_EQ(result[i], data[i]);
}
/** @arg n = 9 */
result = LLV(data, 9);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == data[0]);
BOOST_CHECK(result[7] == data[0]);
BOOST_CHECK(result[8] == data[0]);
BOOST_CHECK(result[9] == data[1]);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], data[0]);
CHECK_EQ(result[7], data[0]);
CHECK_EQ(result[8], data[0]);
CHECK_EQ(result[9], data[1]);
/** @arg n = 10 */
result = LLV(data, 10);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == data[0]);
BOOST_CHECK(result[1] == data[0]);
BOOST_CHECK(result[9] == data[0]);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], data[0]);
CHECK_EQ(result[1], data[0]);
CHECK_EQ(result[9], data[0]);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_LLV_export ) {
TEST_CASE("test_LLV_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/LLV.xml";
@ -95,15 +88,13 @@ BOOST_AUTO_TEST_CASE( test_LLV_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -0,0 +1,172 @@
/*
* test_LLVBARS.cpp
*
* Copyright (c) 2019 hikyuu.org
*
* Created on: 2019-4-14
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/CVAL.h>
#include <hikyuu/indicator/crt/LLVBARS.h>
#include <hikyuu/indicator/crt/KDATA.h>
#include <hikyuu/indicator/crt/PRICELIST.h>
using namespace hku;
/**
* @defgroup test_indicator_LLVBARS test_indicator_LLVBARS
* @ingroup test_hikyuu_indicator_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_LLVBARS") {
StockManager& sm = StockManager::instance();
Stock stk = sm.getStock("sh000001");
KData k = stk.getKData(-10);
Indicator c = CLOSE(k);
Indicator result;
/** @arg n = 0, 低点顺序下降 */
PriceList a;
for (int i = 0; i < 10; ++i) {
a.push_back(10 - i);
}
Indicator data = PRICELIST(a);
result = LLVBARS(data, 0);
CHECK_EQ(result.name(), "LLVBARS");
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], 0);
}
/** @arg n = 0, 低点升序 */
a.clear();
for (int i = 0; i < 10; ++i) {
a.push_back(i);
}
data = PRICELIST(a);
result = LLVBARS(data, 0);
CHECK_EQ(result.name(), "LLVBARS");
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], i);
}
/** @arg n = 0 顺序随机 */
result = LLVBARS(c, 0);
CHECK_EQ(result.name(), "LLVBARS");
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 1);
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 1);
CHECK_EQ(result[4], 2);
CHECK_EQ(result[5], 0);
CHECK_EQ(result[6], 1);
CHECK_EQ(result[9], 0);
/** @arg n = 1 */
result = LLVBARS(c, 1);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], 0);
}
/** @arg n = 5 */
result = LLVBARS(c, 5);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 1);
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 1);
CHECK_EQ(result[4], 2);
CHECK_EQ(result[5], 0);
CHECK_EQ(result[8], 0);
CHECK_EQ(result[9], 0);
/** @arg n = 10 */
result = LLVBARS(c, 10);
CHECK_EQ(result.name(), "LLVBARS");
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 1);
CHECK_EQ(result[5], 0);
CHECK_EQ(result[6], 1);
CHECK_EQ(result[7], 2);
CHECK_EQ(result[9], 0);
/** @arg ind.size() == 1 */
result = LLVBARS(CVAL(1));
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
/** @arg n > ind.size() */
result = LLVBARS(c, 20);
CHECK_GT(20, c.size());
CHECK_EQ(result.name(), "LLVBARS");
CHECK_EQ(result.name(), "LLVBARS");
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 1);
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 1);
CHECK_EQ(result[4], 2);
CHECK_EQ(result[5], 0);
CHECK_EQ(result[6], 1);
CHECK_EQ(result[9], 0);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
TEST_CASE("test_LLVBARS_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/LLVBARS.xml";
Stock stock = sm.getStock("sh000001");
KData kdata = stock.getKData(KQuery(-20));
Indicator x1 = LLVBARS(CLOSE(kdata), 2);
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP(x1);
}
Indicator x2;
{
std::ifstream ifs(filename);
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(x2);
}
CHECK_EQ(x2.name(), "LLVBARS");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/LN.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_LN ) {
TEST_CASE("test_LN") {
Indicator result;
PriceList a;
@ -39,29 +33,28 @@ BOOST_AUTO_TEST_CASE( test_LN ) {
Indicator data = PRICELIST(a);
result = LN(data);
BOOST_CHECK(result.name() == "LN");
BOOST_CHECK(result.size() == 11);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(std::isnan(result[0]));
for (int i = 1; i <10; ++i) {
BOOST_CHECK_CLOSE(result[i], std::log(i), 0.00001);
CHECK_EQ(result.name(), "LN");
CHECK_EQ(result.size(), 11);
CHECK_EQ(result.discard(), 0);
CHECK_UNARY(std::isnan(result[0]));
for (int i = 1; i < 10; ++i) {
CHECK_EQ(result[i], doctest::Approx(std::log(i)));
}
BOOST_CHECK(std::isnan(result[10]));
CHECK_UNARY(std::isnan(result[10]));
result = LN(10);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK_CLOSE(result[0], std::log(10.0), 0.00001);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], doctest::Approx(std::log(10.0)));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_LN_export ) {
TEST_CASE("test_LN_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/LN.xml";
@ -82,15 +75,13 @@ BOOST_AUTO_TEST_CASE( test_LN_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/LOG.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE(test_LOG) {
TEST_CASE("test_LOG") {
Indicator result;
PriceList a;
@ -39,19 +33,19 @@ BOOST_AUTO_TEST_CASE(test_LOG) {
Indicator data = PRICELIST(a);
result = LOG(data);
BOOST_CHECK(result.name() == "LOG");
BOOST_CHECK(result.size() == 11);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(std::isnan(result[0]));
CHECK_EQ(result.name(), "LOG");
CHECK_EQ(result.size(), 11);
CHECK_EQ(result.discard(), 0);
CHECK_UNARY(std::isnan(result[0]));
for (int i = 1; i < 10; ++i) {
BOOST_CHECK_CLOSE(result[i], std::log10(i), 0.00001);
CHECK_EQ(result[i], doctest::Approx(std::log10(i)));
}
BOOST_CHECK(std::isnan(result[10]));
CHECK_UNARY(std::isnan(result[10]));
result = LOG(10);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK_CLOSE(result[0], std::log10(10.0), 0.00001);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], doctest::Approx(std::log10(10.0)));
}
//-----------------------------------------------------------------------------
@ -60,7 +54,7 @@ BOOST_AUTO_TEST_CASE(test_LOG) {
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE(test_LOG_export) {
TEST_CASE("test_LOG_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/LOG.xml";
@ -81,11 +75,11 @@ BOOST_AUTO_TEST_CASE(test_LOG_export) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */

View File

@ -0,0 +1,171 @@
/*
* test_MA.cpp
*
* Created on: 2013-2-12
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/MA.h>
#include <hikyuu/indicator/crt/KDATA.h>
#include <hikyuu/indicator/crt/PRICELIST.h>
using namespace hku;
/**
* @defgroup test_indicator_MA test_indicator_MA
* @ingroup test_hikyuu_indicator_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_MA") {
StockManager& sm = StockManager::instance();
Stock stock = sm.getStock("sh000001");
KData kdata;
Indicator open, ma;
/** @arg n = 3, 但关联数据为空 */
open = OPEN(kdata);
ma = MA(open, 3);
CHECK_EQ(ma.name(), "MA");
CHECK_EQ(ma.size(), 0);
CHECK_EQ(ma.empty(), true);
/** @arg n = 0 时,正常关联数据 */
kdata = stock.getKData(KQuery(-10));
open = OPEN(kdata);
ma = MA(open, 0);
CHECK_EQ(ma.empty(), false);
CHECK_EQ(ma.size(), kdata.size());
CHECK_EQ(ma.discard(), kdata.size());
for (size_t i = 0; i < kdata.size(); ++i) {
CHECK_UNARY(std::isnan(ma[i]));
}
/** @arg n = 10 且数据大小刚好为10 时, 正常关联数据 */
kdata = stock.getKData(KQuery(-10));
open = OPEN(kdata);
ma = MA(open, 10);
CHECK_EQ(ma.empty(), false);
CHECK_EQ(ma.size(), kdata.size());
CHECK_EQ(ma.discard(), 0);
CHECK_LT(std::fabs(ma[0] - 2415.197), 0.00001);
CHECK_LT(std::fabs(ma[1] - 2397.1715), 0.00001);
CHECK_LT(std::fabs(ma[2] - 2395.890), 0.00001);
CHECK_LT(std::fabs(ma[3] - 2392.89075), 0.00001);
CHECK_LT(std::fabs(ma[4] - 2394.1114), 0.00001);
CHECK_LT(std::fabs(ma[5] - 2396.14767), 0.00001);
CHECK_LT(std::fabs(ma[6] - 2395.62443), 0.00001);
CHECK_LT(std::fabs(ma[7] - 2393.03375), 0.00001);
CHECK_LT(std::fabs(ma[8] - 2389.709), 0.00001);
CHECK_LT(std::fabs(ma[9] - 2383.4041), 0.00001);
/** @arg n = 10 且数据大小刚好为9 时, 正常关联数据 */
kdata = stock.getKData(KQuery(-9));
open = OPEN(kdata);
ma = MA(open, 10);
CHECK_EQ(ma.empty(), false);
CHECK_EQ(ma.size(), kdata.size());
CHECK_EQ(ma.discard(), 0);
CHECK_LT(std::fabs(ma[0] - 2379.146), 0.00001);
CHECK_LT(std::fabs(ma[1] - 2386.2365), 0.00001);
CHECK_LT(std::fabs(ma[2] - 2385.45533), 0.00001);
CHECK_LT(std::fabs(ma[3] - 2388.84), 0.00001);
CHECK_LT(std::fabs(ma[7] - 2386.523), 0.00001);
CHECK_LT(std::fabs(ma[8] - 2379.87156), 0.00001);
/** @arg n = 10 且数据大小为11 时, 正常关联数据 */
kdata = stock.getKData(KQuery(-11));
open = OPEN(kdata);
ma = MA(open, 10);
CHECK_EQ(ma.empty(), false);
CHECK_EQ(ma.size(), kdata.size());
CHECK_EQ(ma.discard(), 0);
CHECK_LT(std::fabs(ma[0] - 2400.984), 0.00001);
CHECK_LT(std::fabs(ma[8] - 2393.91711), 0.00001);
CHECK_LT(std::fabs(ma[9] - 2390.8365), 0.00001);
CHECK_LT(std::fabs(ma[10] - 2383.4041), 0.00001);
/** @arg n = 1 */
kdata = stock.getKData(KQuery(-11));
open = OPEN(kdata);
ma = MA(open, 1);
CHECK_EQ(ma.empty(), false);
CHECK_EQ(ma.size(), kdata.size());
CHECK_EQ(ma.discard(), 0);
for (size_t i = 0; i < open.size(); ++i) {
CHECK_LT(std::fabs(ma[i] - open[i]), 0.0001);
}
/** @arg 源数据本身带有discard不等于0 */
PriceList data;
for (int i = 0; i < 10; ++i) {
data.push_back(i);
}
Indicator d = PRICELIST(data);
Indicator ma1 = MA(d, 2);
Indicator ma2 = MA(ma1, 2);
CHECK_EQ(ma1.discard(), 0);
CHECK_EQ(ma2.discard(), 0);
CHECK_EQ(ma1[0], data[0]);
CHECK_EQ(ma1[1], (data[0] + data[1]) / 2);
CHECK_EQ(ma1[2], 1.5);
CHECK_EQ(ma1[3], 2.5);
CHECK_EQ(ma2[0], ma1[0]);
CHECK_EQ(ma2[1], (ma1[0] + ma1[1]) / 2);
CHECK_EQ(ma2[2], 1.0);
CHECK_EQ(ma2[3], 2.0);
/** @arg operator() */
ma = MA(2);
ma1 = MA(d, 2);
ma2 = ma(d);
CHECK_EQ(ma.size(), 0);
CHECK_EQ(ma1.size(), 10);
CHECK_EQ(ma1.size(), ma2.size());
for (size_t i = 0; i < ma1.size(); ++i) {
CHECK_EQ(ma1[i], ma2[i]);
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
TEST_CASE("test_MA_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/MA.xml";
Stock stock = sm.getStock("sh000001");
KData kdata = stock.getKData(KQuery(-20));
Indicator ma1 = MA(CLOSE(kdata), 10);
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP(ma1);
}
Indicator ma2;
{
std::ifstream ifs(filename);
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(ma2);
}
CHECK_EQ(ma2.name(), "MA");
CHECK_EQ(ma1.size(), ma2.size());
CHECK_EQ(ma1.discard(), ma2.discard());
CHECK_EQ(ma1.getResultNumber(), ma2.getResultNumber());
for (size_t i = 0; i < ma1.size(); ++i) {
CHECK_EQ(ma1[i], doctest::Approx(ma2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -0,0 +1,196 @@
/*
* test_MACD.cpp
*
* Created on: 2013-4-11
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/KDATA.h>
#include <hikyuu/indicator/crt/MACD.h>
#include <hikyuu/indicator/crt/PRICELIST.h>
#include <hikyuu/indicator/crt/EMA.h>
using namespace hku;
/**
* @defgroup test_indicator_MACD test_indicator_MACD
* @ingroup test_hikyuu_indicator_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_MACD") {
PriceList d;
for (size_t i = 0; i < 20; ++i) {
d.push_back(i);
}
Indicator ind = PRICELIST(d);
Indicator macd, bar, diff, dea;
Indicator ema1, ema2, fast, slow, bmacd;
/** @arg 源数据为空 */
macd = MACD(Indicator(), 12, 26, 9);
CHECK_EQ(macd.size(), 0);
CHECK_EQ(macd.empty(), true);
/** @arg n1 = n2 = n3 = 1*/
macd = MACD(ind, 1, 1, 1);
CHECK_EQ(macd.getResultNumber(), 3);
bar = macd.getResult(0);
diff = macd.getResult(1);
dea = macd.getResult(2);
CHECK_EQ(bar.size(), 20);
CHECK_EQ(diff.size(), 20);
CHECK_EQ(dea.size(), 20);
CHECK_EQ(diff[0], 0);
CHECK_EQ(diff[1], 0);
CHECK_EQ(diff[19], 0);
CHECK_EQ(dea[0], 0);
CHECK_EQ(dea[1], 0);
CHECK_EQ(dea[19], 0);
CHECK_EQ(bar[0], 0);
CHECK_EQ(bar[1], 0);
CHECK_EQ(bar[19], 0);
/** @arg n1 = 1 n2 = 2 n3 = 3*/
macd = MACD(ind, 1, 2, 3);
CHECK_EQ(macd.size(), 20);
CHECK_EQ(macd.discard(), 0);
bar = macd.getResult(0);
diff = macd.getResult(1);
dea = macd.getResult(2);
ema1 = EMA(ind, 1);
ema2 = EMA(ind, 2);
fast = ema1 - ema2;
slow = EMA(fast, 3);
bmacd = fast - slow;
CHECK_EQ(bar.size(), 20);
CHECK_EQ(diff.size(), 20);
CHECK_EQ(dea.size(), 20);
CHECK_EQ(diff[0], fast[0]);
CHECK_EQ(diff[1], fast[1]);
CHECK_EQ(diff[19], fast[19]);
CHECK_EQ(dea[0], slow[0]);
CHECK_LT(std::fabs(dea[1] - slow[1]), 0.0001);
CHECK_EQ(dea[19], slow[19]);
CHECK_EQ(bar[0], bmacd[0]);
CHECK_EQ(bar[1], bmacd[1]);
CHECK_EQ(bar[19], bmacd[19]);
/** @arg n1 = 3 n2 = 2 n3 = 1*/
macd = MACD(ind, 3, 2, 1);
CHECK_EQ(macd.size(), 20);
CHECK_EQ(macd.discard(), 0);
bar = macd.getResult(0);
diff = macd.getResult(1);
dea = macd.getResult(2);
ema1 = EMA(ind, 3);
ema2 = EMA(ind, 2);
fast = ema1 - ema2;
slow = EMA(fast, 1);
bmacd = fast - slow;
CHECK_EQ(bar.size(), 20);
CHECK_EQ(diff.size(), 20);
CHECK_EQ(dea.size(), 20);
CHECK_EQ(diff[0], fast[0]);
CHECK_EQ(diff[1], fast[1]);
CHECK_EQ(diff[19], fast[19]);
CHECK_EQ(dea[0], slow[0]);
CHECK_EQ(dea[1], slow[1]);
CHECK_EQ(dea[19], slow[19]);
CHECK_EQ(bar[0], bmacd[0]);
CHECK_EQ(bar[1], bmacd[1]);
CHECK_EQ(bar[19], bmacd[19]);
/** @arg n1 = 3 n2 = 5 n3 = 2*/
macd = MACD(ind, 3, 5, 2);
CHECK_EQ(macd.size(), 20);
CHECK_EQ(macd.discard(), 0);
bar = macd.getResult(0);
diff = macd.getResult(1);
dea = macd.getResult(2);
ema1 = EMA(ind, 3);
ema2 = EMA(ind, 5);
fast = ema1 - ema2;
slow = EMA(fast, 2);
bmacd = fast - slow;
CHECK_EQ(bar.size(), 20);
CHECK_EQ(diff.size(), 20);
CHECK_EQ(dea.size(), 20);
CHECK_EQ(diff[0], fast[0]);
CHECK_EQ(diff[1], fast[1]);
CHECK_EQ(diff[19], fast[19]);
CHECK_EQ(dea[0], slow[0]);
CHECK_EQ(dea[1], slow[1]);
CHECK_EQ(dea[19], slow[19]);
CHECK_EQ(bar[0], bmacd[0]);
CHECK_EQ(bar[1], bmacd[1]);
CHECK_EQ(bar[19], bmacd[19]);
/** @arg operator() */
Indicator expect = MACD(ind, 3, 5, 2);
Indicator tmp = MACD(3, 5, 2);
Indicator result = tmp(ind);
CHECK_EQ(result.size(), expect.size());
for (size_t i = 0; i < expect.size(); ++i) {
CHECK_EQ(result.get(i, 0), expect.get(i, 0));
CHECK_EQ(result.get(i, 1), expect.get(i, 1));
CHECK_EQ(result.get(i, 2), expect.get(i, 2));
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
TEST_CASE("test_MACD_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/MACD.xml";
Stock stock = sm.getStock("sh000001");
KData kdata = stock.getKData(KQuery(-20));
Indicator ma1 = MACD(CLOSE(kdata));
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP(ma1);
}
Indicator ma2;
{
std::ifstream ifs(filename);
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(ma2);
}
CHECK_EQ(ma1.size(), ma2.size());
CHECK_EQ(ma1.discard(), ma2.discard());
CHECK_EQ(ma1.getResultNumber(), ma2.getResultNumber());
for (size_t i = 0; i < ma1.size(); ++i) {
CHECK_EQ(ma1.get(i, 0), doctest::Approx(ma2.get(i, 0)));
CHECK_EQ(ma1.get(i, 1), doctest::Approx(ma2.get(i, 1)));
CHECK_EQ(ma1.get(i, 2), doctest::Approx(ma2.get(i, 2)));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/KDATA.h>
@ -28,33 +21,32 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_MAX ) {
TEST_CASE("test_MAX") {
/** @arg n > 0 */
KData k =getStock("sh600004").getKData(KQuery(-8));
KData k = getStock("sh600004").getKData(KQuery(-8));
Indicator C = CLOSE(k);
Indicator O = OPEN(k);
Indicator x = MAX(C, O);
BOOST_CHECK(x.name() == "MAX");
BOOST_CHECK(x.size() == 8);
BOOST_CHECK(x.discard() == 0);
CHECK_EQ(x.name(), "MAX");
CHECK_EQ(x.size(), 8);
CHECK_EQ(x.discard(), 0);
size_t total = x.size();
for (int i = 0; i < total; i++) {
if (C[i] > O[i]) {
BOOST_CHECK(x[i] == C[i]);
CHECK_EQ(x[i], C[i]);
} else {
BOOST_CHECK(x[i] == O[i]);
CHECK_EQ(x[i], O[i]);
}
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_MAX_export ) {
TEST_CASE("test_MAX_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/MAX.xml";
@ -75,14 +67,14 @@ BOOST_AUTO_TEST_CASE( test_MAX_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.name(), x2.name());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/KDATA.h>
@ -28,34 +21,33 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_MIN ) {
TEST_CASE("test_MIN") {
/** @arg n > 0 */
KData k =getStock("sh600004").getKData(KQuery(-8));
KData k = getStock("sh600004").getKData(KQuery(-8));
Indicator C = CLOSE(k);
Indicator O = OPEN(k);
Indicator x = MIN(C, O);
BOOST_CHECK(x.name() == "MIN");
BOOST_CHECK(x.size() == 8);
BOOST_CHECK(x.discard() == 0);
CHECK_EQ(x.name(), "MIN");
CHECK_EQ(x.size(), 8);
CHECK_EQ(x.discard(), 0);
size_t total = x.size();
for (int i = 0; i < total; i++) {
if (C[i] < O[i]) {
BOOST_CHECK(x[i] == C[i]);
CHECK_EQ(x[i], C[i]);
} else {
BOOST_CHECK(x[i] == O[i]);
CHECK_EQ(x[i], O[i]);
}
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_MIN_export ) {
TEST_CASE("test_MIN_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/MIN.xml";
@ -76,14 +68,14 @@ BOOST_AUTO_TEST_CASE( test_MIN_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.name(), x2.name());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -4,14 +4,7 @@
* Created on: 201942
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/NOT.h>
@ -27,7 +20,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_NOT ) {
TEST_CASE("test_NOT") {
Indicator result;
PriceList a;
@ -38,22 +31,21 @@ BOOST_AUTO_TEST_CASE( test_NOT ) {
Indicator data = PRICELIST(a);
result = NOT(data);
BOOST_CHECK(result.name() == "NOT");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 1.0);
for (int i = 1; i <10; ++i) {
BOOST_CHECK(result[i] == 0.0);
CHECK_EQ(result.name(), "NOT");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 1.0);
for (int i = 1; i < 10; ++i) {
CHECK_EQ(result[i], 0.0);
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_NOT_export ) {
TEST_CASE("test_NOT_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/NOT.xml";
@ -74,15 +66,14 @@ BOOST_AUTO_TEST_CASE( test_NOT_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.name(), x2.name());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -1,19 +1,13 @@
/*
* test_POW.cpp
*
*
* Copyright (c) 2019 hikyuu.org
*
* Created on: 201942
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/POW.h>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_POW ) {
TEST_CASE("test_POW") {
Indicator result;
PriceList a;
@ -40,27 +34,26 @@ BOOST_AUTO_TEST_CASE( test_POW ) {
Indicator data = PRICELIST(a);
result = POW(data, 2);
BOOST_CHECK(result.name() == "POW");
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == std::pow(data[i], 2));
CHECK_EQ(result.name(), "POW");
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], std::pow(data[i], 2));
}
result = POW(-11, 3);
BOOST_CHECK(result.name() == "POW");
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == std::pow(-11, 3));
CHECK_EQ(result.name(), "POW");
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], std::pow(-11, 3));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_POW_export ) {
TEST_CASE("test_POW_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/POW.xml";
@ -81,15 +74,14 @@ BOOST_AUTO_TEST_CASE( test_POW_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.name(), x2.name());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/PRICELIST.h>
@ -26,31 +20,31 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_PRICELIST ) {
TEST_CASE("test_PRICELIST") {
PriceList tmp_list;
Indicator result;
/** @arg PriceList 为空 */
result = PRICELIST(tmp_list);
BOOST_CHECK(result.size() == tmp_list.size());
BOOST_CHECK(result.empty() == true);
CHECK_EQ(result.size(), tmp_list.size());
CHECK_EQ(result.empty(), true);
/** @arg PriceList 非空 */
for (size_t i = 0; i < 10; ++i) {
tmp_list.push_back(i);
}
result = PRICELIST(tmp_list);
BOOST_CHECK(result.size() == tmp_list.size());
BOOST_CHECK(result.empty() == false);
CHECK_EQ(result.size(), tmp_list.size());
CHECK_EQ(result.empty(), false);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == tmp_list[i]);
CHECK_EQ(result[i], tmp_list[i]);
}
/** @arg 数组指针为空 */
price_t *p_tmp = NULL;
price_t* p_tmp = NULL;
result = PRICELIST(p_tmp, 10);
BOOST_CHECK(result.size() == 0);
BOOST_CHECK(result.empty() == true);
CHECK_EQ(result.size(), 0);
CHECK_EQ(result.empty(), true);
/** @arg 数组指针非空 */
price_t tmp[10];
@ -59,28 +53,28 @@ BOOST_AUTO_TEST_CASE( test_PRICELIST ) {
}
result = PRICELIST(tmp, 10);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == tmp[i]);
CHECK_EQ(result[i], tmp[i]);
}
/** @arg 从PriceList构造 */
result = PRICELIST(tmp_list);
BOOST_CHECK(result.size() == 10);
CHECK_EQ(result.size(), 10);
for (size_t i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == tmp_list[i]);
CHECK_EQ(result[i], tmp_list[i]);
}
/** @arg 从PriceLIst discard为1 */
result = PRICELIST(tmp_list, 1);
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.discard() == 1);
BOOST_CHECK(std::isnan(result[0]));
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 1);
CHECK_UNARY(std::isnan(result[0]));
for (size_t i = 1; i < 10; ++i) {
BOOST_CHECK(result[i] == tmp_list[i]);
CHECK_EQ(result[i], tmp_list[i]);
}
/** @arg 待转化数据为IndicatorIndicator为空 */
result = PRICELIST(Indicator());
BOOST_CHECK(result.size() == 0);
CHECK_EQ(result.size(), 0);
/** @arg 待转化数据为Indicator, result_num=0 */
StockManager& sm = StockManager::instance();
@ -88,31 +82,30 @@ BOOST_AUTO_TEST_CASE( test_PRICELIST ) {
KQuery query(0, 30);
KData kdata = stock.getKData(query);
Indicator ikdata = KDATA(kdata);
BOOST_CHECK(ikdata.size() == 30);
CHECK_EQ(ikdata.size(), 30);
result = PRICELIST(ikdata);
BOOST_CHECK(result.size() == ikdata.size());
BOOST_CHECK(result.discard() == ikdata.discard());
CHECK_EQ(result.size(), ikdata.size());
CHECK_EQ(result.discard(), ikdata.discard());
for (size_t i = 0; i < result.size(); ++i) {
BOOST_CHECK(result[i] == ikdata[i]);
CHECK_EQ(result[i], ikdata[i]);
}
/** @arg 待转化数据为Indicator, result_num=1 */
result = PRICELIST(ikdata, 1);
BOOST_CHECK(result.size() == ikdata.size());
BOOST_CHECK(result.discard() == ikdata.discard());
CHECK_EQ(result.size(), ikdata.size());
CHECK_EQ(result.discard(), ikdata.discard());
for (size_t i = 0; i < result.size(); ++i) {
BOOST_CHECK(result[i] == ikdata.get(i, 1));
CHECK_EQ(result[i], ikdata.get(i, 1));
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_PRICELIST_export ) {
TEST_CASE("test_PRICELIST_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/PRICELIST.xml";
@ -136,11 +129,11 @@ BOOST_AUTO_TEST_CASE( test_PRICELIST_export ) {
ia >> BOOST_SERIALIZATION_NVP(ma2);
}
BOOST_CHECK(ma1.size() == ma2.size());
BOOST_CHECK(ma1.discard() == ma2.discard());
BOOST_CHECK(ma1.getResultNumber() == ma2.getResultNumber());
CHECK_EQ(ma1.size(), ma2.size());
CHECK_EQ(ma1.discard(), ma2.discard());
CHECK_EQ(ma1.getResultNumber(), ma2.getResultNumber());
for (size_t i = 0; i < ma1.size(); ++i) {
BOOST_CHECK_CLOSE(ma1[i], ma2[i], 0.00001);
CHECK_EQ(ma1[i], doctest::Approx(ma2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/REF.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_REF ) {
TEST_CASE("test_REF") {
Indicator result;
PriceList a;
@ -39,36 +33,35 @@ BOOST_AUTO_TEST_CASE( test_REF ) {
/** @arg n = 0 */
result = REF(data, 0);
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == data[i]);
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], data[i]);
}
/** @arg n = 1 */
result = REF(data, 1);
BOOST_CHECK(result.discard() == 1);
CHECK_EQ(result.discard(), 1);
for (int i = 1; i < 10; ++i) {
BOOST_CHECK(result[i] == data[i-1]);
CHECK_EQ(result[i], data[i - 1]);
}
/** @arg n = 9 */
result = REF(data, 9);
BOOST_CHECK(result.discard() == 9);
BOOST_CHECK(result[9] == data[0]);
CHECK_EQ(result.discard(), 9);
CHECK_EQ(result[9], data[0]);
/** @arg n = 10 */
result = REF(data, 10);
BOOST_CHECK(result.discard() == 10);
CHECK_EQ(result.discard(), 10);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_REF_export ) {
TEST_CASE("test_REF_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/REF.xml";
@ -89,15 +82,13 @@ BOOST_AUTO_TEST_CASE( test_REF_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_REVERSE.cpp
*
* Copyright (c) 2019 hikyuu.org
*
*
* Created on: 2019-5-1
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/REVERSE.h>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_REVERSE ) {
TEST_CASE("test_REVERSE") {
Indicator result;
PriceList a;
@ -40,26 +34,25 @@ BOOST_AUTO_TEST_CASE( test_REVERSE ) {
Indicator data = PRICELIST(a);
result = REVERSE(data);
BOOST_CHECK(result.name() == "REVERSE");
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == -data[i]);
CHECK_EQ(result.name(), "REVERSE");
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], -data[i]);
}
result = REVERSE(-11);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 11);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 11);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_REVERSE_export ) {
TEST_CASE("test_REVERSE_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/REVERSE.xml";
@ -80,16 +73,14 @@ BOOST_AUTO_TEST_CASE( test_REVERSE_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "REVERSE");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "REVERSE");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,19 +2,13 @@
* test_ROC.cpp
*
* Copyright (c) 2019, hikyuu.org
*
*
* Created on: 2019-5-18
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include <fstream>
#include "doctest/doctest.h"
#include < fstream >
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/ROC.h>
#include <hikyuu/indicator/crt/KDATA.h>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ROC ) {
TEST_CASE("test_ROC") {
Indicator result;
PriceList a;
@ -39,35 +33,34 @@ BOOST_AUTO_TEST_CASE( test_ROC ) {
Indicator data = PRICELIST(a);
result = ROC(data, 1);
BOOST_CHECK(result.name() == "ROC");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 1);
BOOST_CHECK(std::isnan(result[0]));
BOOST_CHECK(result[1] == 0);
BOOST_CHECK(result[2] == 100);
BOOST_CHECK(result[3] == 50);
BOOST_CHECK(result[5] == 25);
BOOST_CHECK(result[9] == 12.5);
CHECK_EQ(result.name(), "ROC");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 1);
CHECK_UNARY(std::isnan(result[0]));
CHECK_EQ(result[1], 0);
CHECK_EQ(result[2], 100);
CHECK_EQ(result[3], 50);
CHECK_EQ(result[5], 25);
CHECK_EQ(result[9], 12.5);
result = ROC(data, 2);
BOOST_CHECK(result.name() == "ROC");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 2);
BOOST_CHECK(std::isnan(result[0]));
BOOST_CHECK(std::isnan(result[1]));
BOOST_CHECK(result[2] == 0);
BOOST_CHECK(result[3] == 200);
BOOST_CHECK(result[4] == 100);
CHECK_EQ(result.name(), "ROC");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 2);
CHECK_UNARY(std::isnan(result[0]));
CHECK_UNARY(std::isnan(result[1]));
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 200);
CHECK_EQ(result[4], 100);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ROC_export ) {
TEST_CASE("test_ROC_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/ROC.xml";
@ -88,16 +81,14 @@ BOOST_AUTO_TEST_CASE( test_ROC_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "ROC");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "ROC");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_ROCP.cpp
*
* Copyright (c) 2019, hikyuu.org
*
*
* Created on: 2019-5-18
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/ROCP.h>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ROCP ) {
TEST_CASE("test_ROCP") {
Indicator result;
PriceList a;
@ -39,35 +33,34 @@ BOOST_AUTO_TEST_CASE( test_ROCP ) {
Indicator data = PRICELIST(a);
result = ROCP(data, 1);
BOOST_CHECK(result.name() == "ROCP");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 1);
BOOST_CHECK(std::isnan(result[0]));
BOOST_CHECK(result[1] == 0);
BOOST_CHECK(result[2] == 1);
BOOST_CHECK(result[3] == 0.5);
BOOST_CHECK(result[5] == 0.25);
BOOST_CHECK(result[9] == 0.125);
CHECK_EQ(result.name(), "ROCP");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 1);
CHECK_UNARY(std::isnan(result[0]));
CHECK_EQ(result[1], 0);
CHECK_EQ(result[2], 1);
CHECK_EQ(result[3], 0.5);
CHECK_EQ(result[5], 0.25);
CHECK_EQ(result[9], 0.125);
result = ROCP(data, 2);
BOOST_CHECK(result.name() == "ROCP");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 2);
BOOST_CHECK(std::isnan(result[0]));
BOOST_CHECK(std::isnan(result[1]));
BOOST_CHECK(result[2] == 0);
BOOST_CHECK(result[3] == 2);
BOOST_CHECK(result[4] == 1);
CHECK_EQ(result.name(), "ROCP");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 2);
CHECK_UNARY(std::isnan(result[0]));
CHECK_UNARY(std::isnan(result[1]));
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 2);
CHECK_EQ(result[4], 1);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ROCP_export ) {
TEST_CASE("test_ROCP_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/ROCP.xml";
@ -88,16 +81,14 @@ BOOST_AUTO_TEST_CASE( test_ROCP_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "ROCP");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "ROCP");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_ROCR.cpp
*
* Copyright (c) 2019, hikyuu.org
*
*
* Created on: 2019-5-18
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/ROCR.h>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ROCR ) {
TEST_CASE("test_ROCR") {
Indicator result;
PriceList a;
@ -39,35 +33,34 @@ BOOST_AUTO_TEST_CASE( test_ROCR ) {
Indicator data = PRICELIST(a);
result = ROCR(data, 1);
BOOST_CHECK(result.name() == "ROCR");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 1);
BOOST_CHECK(std::isnan(result[0]));
BOOST_CHECK(result[1] == 0);
BOOST_CHECK(result[2] == 2);
BOOST_CHECK(result[3] == 1.5);
BOOST_CHECK(result[5] == 1.25);
BOOST_CHECK(result[9] == 1.125);
CHECK_EQ(result.name(), "ROCR");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 1);
CHECK_UNARY(std::isnan(result[0]));
CHECK_EQ(result[1], 0);
CHECK_EQ(result[2], 2);
CHECK_EQ(result[3], 1.5);
CHECK_EQ(result[5], 1.25);
CHECK_EQ(result[9], 1.125);
result = ROCR(data, 2);
BOOST_CHECK(result.name() == "ROCR");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 2);
BOOST_CHECK(std::isnan(result[0]));
BOOST_CHECK(std::isnan(result[1]));
BOOST_CHECK(result[2] == 0);
BOOST_CHECK(result[3] == 3);
BOOST_CHECK(result[4] == 2);
CHECK_EQ(result.name(), "ROCR");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 2);
CHECK_UNARY(std::isnan(result[0]));
CHECK_UNARY(std::isnan(result[1]));
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 3);
CHECK_EQ(result[4], 2);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ROCR_export ) {
TEST_CASE("test_ROCR_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/ROCR.xml";
@ -88,16 +81,14 @@ BOOST_AUTO_TEST_CASE( test_ROCR_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "ROCR");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "ROCR");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_ROCR100.cpp
*
* Copyright (c) 2019, hikyuu.org
*
*
* Created on: 2019-5-18
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/ROCR100.h>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ROCR100 ) {
TEST_CASE("test_ROCR100") {
Indicator result;
PriceList a;
@ -39,35 +33,34 @@ BOOST_AUTO_TEST_CASE( test_ROCR100 ) {
Indicator data = PRICELIST(a);
result = ROCR100(data, 1);
BOOST_CHECK(result.name() == "ROCR100");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 1);
BOOST_CHECK(std::isnan(result[0]));
BOOST_CHECK(result[1] == 0);
BOOST_CHECK(result[2] == 200);
BOOST_CHECK(result[3] == 150);
BOOST_CHECK(result[5] == 125);
BOOST_CHECK(result[9] == 112.5);
CHECK_EQ(result.name(), "ROCR100");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 1);
CHECK_UNARY(std::isnan(result[0]));
CHECK_EQ(result[1], 0);
CHECK_EQ(result[2], 200);
CHECK_EQ(result[3], 150);
CHECK_EQ(result[5], 125);
CHECK_EQ(result[9], 112.5);
result = ROCR100(data, 2);
BOOST_CHECK(result.name() == "ROCR100");
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result.discard() == 2);
BOOST_CHECK(std::isnan(result[0]));
BOOST_CHECK(std::isnan(result[1]));
BOOST_CHECK(result[2] == 0);
BOOST_CHECK(result[3] == 300);
BOOST_CHECK(result[4] == 200);
CHECK_EQ(result.name(), "ROCR100");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 2);
CHECK_UNARY(std::isnan(result[0]));
CHECK_UNARY(std::isnan(result[1]));
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 300);
CHECK_EQ(result[4], 200);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ROCR100_export ) {
TEST_CASE("test_ROCR100_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/ROCR100.xml";
@ -88,16 +81,14 @@ BOOST_AUTO_TEST_CASE( test_ROCR100_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "ROCR100");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "ROCR100");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/ROUND.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ROUND ) {
TEST_CASE("test_ROUND") {
Indicator result;
PriceList a;
@ -39,28 +33,27 @@ BOOST_AUTO_TEST_CASE( test_ROUND ) {
Indicator data = PRICELIST(a);
result = ROUND(data, 2);
BOOST_CHECK(result.name() == "ROUND");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == 4);
BOOST_CHECK_CLOSE(result[0], 1.32, 0.001);
BOOST_CHECK_CLOSE(result[1], 0.30, 0.001);
BOOST_CHECK_CLOSE(result[2], 0.30, 0.001);
BOOST_CHECK_CLOSE(result[3], 2.68, 0.001);
CHECK_EQ(result.name(), "ROUND");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 4);
CHECK_EQ(result[0], doctest::Approx(1.32));
CHECK_EQ(result[1], doctest::Approx(0.30));
CHECK_EQ(result[2], doctest::Approx(0.30));
CHECK_EQ(result[3], doctest::Approx(2.68));
result = ROUND(-11.15, 1);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK_CLOSE(result[0], -11.2, 0.01);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], doctest::Approx(-11.2));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ROUND_export ) {
TEST_CASE("test_ROUND_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/ROUND.xml";
@ -81,16 +74,14 @@ BOOST_AUTO_TEST_CASE( test_ROUND_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "ROUND");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "ROUND");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/ROUNDDOWN.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ROUNDDOWN ) {
TEST_CASE("test_ROUNDDOWN") {
Indicator result;
PriceList a;
@ -38,27 +32,26 @@ BOOST_AUTO_TEST_CASE( test_ROUNDDOWN ) {
Indicator data = PRICELIST(a);
result = ROUNDDOWN(data, 2);
BOOST_CHECK(result.name() == "ROUNDDOWN");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == 3);
BOOST_CHECK_CLOSE(result[0], 1.32, 0.001);
BOOST_CHECK_CLOSE(result[1], 0.30, 0.001);
BOOST_CHECK_CLOSE(result[2], 0.30, 0.001);
CHECK_EQ(result.name(), "ROUNDDOWN");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], doctest::Approx(1.32));
CHECK_EQ(result[1], doctest::Approx(0.30));
CHECK_EQ(result[2], doctest::Approx(0.30));
result = ROUNDDOWN(-11.15, 1);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK_CLOSE(result[0], -11.1, 0.01);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], doctest::Approx(-11.1));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ROUNDDOWN_export ) {
TEST_CASE("test_ROUNDDOWN_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/ROUNDDOWN.xml";
@ -79,16 +72,14 @@ BOOST_AUTO_TEST_CASE( test_ROUNDDOWN_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "ROUNDDOWN");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "ROUNDDOWN");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/ROUNDUP.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ROUNDUP ) {
TEST_CASE("test_ROUNDUP") {
Indicator result;
PriceList a;
@ -38,27 +32,26 @@ BOOST_AUTO_TEST_CASE( test_ROUNDUP ) {
Indicator data = PRICELIST(a);
result = ROUNDUP(data, 2);
BOOST_CHECK(result.name() == "ROUNDUP");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == 3);
BOOST_CHECK_CLOSE(result[0], 1.33, 0.001);
BOOST_CHECK_CLOSE(result[1], 0.31, 0.001);
BOOST_CHECK_CLOSE(result[2], 0.31, 0.001);
CHECK_EQ(result.name(), "ROUNDUP");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], doctest::Approx(1.33));
CHECK_EQ(result[1], doctest::Approx(0.31));
CHECK_EQ(result[2], doctest::Approx(0.31));
result = ROUNDUP(-11.11, 1);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK_CLOSE(result[0], -11.2, 0.01);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], doctest::Approx(-11.2));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ROUNDUP_export ) {
TEST_CASE("test_ROUNDUP_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/ROUNDUP.xml";
@ -79,16 +72,14 @@ BOOST_AUTO_TEST_CASE( test_ROUNDUP_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "ROUNDUP");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "ROUNDUP");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -0,0 +1,167 @@
/*
* test_SAFTYLOSS.cpp
*
* Created on: 2013-4-12
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/SAFTYLOSS.h>
#include <hikyuu/indicator/crt/KDATA.h>
using namespace hku;
/**
* @defgroup test_indicator_SAFTYLOSS test_indicator_SAFTYLOSS
* @ingroup test_hikyuu_indicator_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_SAFTYLOSS") {
StockManager& sm = StockManager::instance();
Stock stock = sm.getStock("sh600000");
KQuery query;
KData kdata;
Indicator close, result;
/** @arg 源数据为空 */
result = SAFTYLOSS(CLOSE(kdata), 2, 1);
CHECK_EQ(result.empty(), true);
CHECK_EQ(result.size(), 0);
CHECK_EQ(result.discard(), 0);
/** @arg 参数n1、n2非法 */
query = KQuery(0, 20);
kdata = stock.getKData(query);
close = CLOSE(kdata);
result = SAFTYLOSS(close, 1, 1);
CHECK_EQ(result.empty(), false);
CHECK_EQ(result.size(), close.size());
CHECK_EQ(result.discard(), close.size());
for (size_t i = 0; i < result.size(); ++i) {
CHECK_UNARY(std::isnan(result[i]));
}
result = SAFTYLOSS(close, 0, 0);
CHECK_EQ(result.empty(), false);
CHECK_EQ(result.size(), close.size());
CHECK_EQ(result.discard(), close.size());
result = SAFTYLOSS(close, 2, 0);
CHECK_EQ(result.empty(), false);
CHECK_EQ(result.size(), close.size());
CHECK_EQ(result.discard(), close.size());
/** @arg 正常参数 */
result = SAFTYLOSS(close, 2, 1, 1.0);
CHECK_EQ(result.empty(), false);
CHECK_EQ(result.size(), close.size());
CHECK_EQ(result.discard(), 1);
CHECK_UNARY(std::isnan(result[0]));
CHECK_EQ(result[1], 27.67);
CHECK_EQ(result[2], 28.05);
CHECK_EQ(result[3], 27.45);
CHECK_LT(std::fabs(result[19] - 25.54), 0.0001);
result = SAFTYLOSS(close, 2, 2, 1.0);
CHECK_EQ(result.empty(), false);
CHECK_EQ(result.size(), close.size());
CHECK_EQ(result.discard(), 2);
CHECK_UNARY(std::isnan(result[0]));
CHECK_UNARY(std::isnan(result[1]));
CHECK_EQ(result[2], 28.05);
CHECK_EQ(result[3], 28.05);
CHECK_EQ(result[4], 27.45);
CHECK_LT(std::fabs(result[19] - 25.54), 0.0001);
result = SAFTYLOSS(close, 3, 2, 2.0);
CHECK_EQ(result.empty(), false);
CHECK_EQ(result.size(), close.size());
CHECK_EQ(result.discard(), 3);
CHECK_UNARY(std::isnan(result[0]));
CHECK_UNARY(std::isnan(result[1]));
CHECK_UNARY(std::isnan(result[2]));
CHECK_LT(std::fabs(result[3] - 27.97), 0.0001);
CHECK_LT(std::fabs(result[4] - 27.15), 0.0001);
CHECK_LT(std::fabs(result[5] - 25.05), 0.0001);
CHECK_LT(std::fabs(result[19] - 24.84), 0.0001);
result = SAFTYLOSS(close, 3, 3, 2.0);
CHECK_EQ(result.empty(), false);
CHECK_EQ(result.size(), close.size());
CHECK_EQ(result.discard(), 4);
CHECK_UNARY(std::isnan(result[0]));
CHECK_UNARY(std::isnan(result[1]));
CHECK_UNARY(std::isnan(result[2]));
CHECK_UNARY(std::isnan(result[3]));
CHECK_LT(std::fabs(result[4] - 27.97), 0.0001);
CHECK_LT(std::fabs(result[5] - 27.15), 0.0001);
CHECK_LT(std::fabs(result[6] - 26.7), 0.0001);
CHECK_LT(std::fabs(result[19] - 25.68), 0.0001);
result = SAFTYLOSS(close, 10, 3, 2.0);
CHECK_EQ(result.empty(), false);
CHECK_EQ(result.size(), close.size());
CHECK_EQ(result.discard(), 11);
CHECK_UNARY(std::isnan(result[0]));
CHECK_UNARY(std::isnan(result[1]));
CHECK_UNARY(std::isnan(result[2]));
CHECK_UNARY(std::isnan(result[10]));
CHECK_LT(std::fabs(result[11] - 25.7486), 0.0001);
CHECK_LT(std::fabs(result[12] - 25.79), 0.0001);
CHECK_LT(std::fabs(result[13] - 26.03), 0.0001);
CHECK_LT(std::fabs(result[19] - 26.105), 0.0001);
/** @arg operator() */
Indicator ind = SAFTYLOSS(10, 3, 2.0);
CHECK_EQ(ind.size(), 0);
result = ind(close);
Indicator expect = SAFTYLOSS(close, 10, 3, 2.0);
CHECK_EQ(result.size(), expect.size());
CHECK_UNARY(result.size() != 0);
CHECK_EQ(result.discard(), expect.discard());
for (size_t i = result.discard(); i < expect.size(); ++i) {
CHECK_EQ(result[i], expect[i]);
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
TEST_CASE("test_SAFTYLOSS_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/SAFTYLOSS.xml";
Stock stock = sm.getStock("sh000001");
KData kdata = stock.getKData(KQuery(-20));
Indicator ma1 = SAFTYLOSS(CLOSE(kdata));
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP(ma1);
}
Indicator ma2;
{
std::ifstream ifs(filename);
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(ma2);
}
CHECK_EQ(ma1.size(), ma2.size());
CHECK_EQ(ma1.discard(), ma2.discard());
CHECK_EQ(ma1.getResultNumber(), ma2.getResultNumber());
for (size_t i = ma1.discard(); i < ma1.size(); ++i) {
CHECK_EQ(ma1[i], doctest::Approx(ma2[i]).epsilon(0.00001));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/SGN.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_SGN ) {
TEST_CASE("test_SGN") {
Indicator result;
PriceList a;
@ -38,37 +32,36 @@ BOOST_AUTO_TEST_CASE( test_SGN ) {
Indicator data = PRICELIST(a);
result = SGN(data);
BOOST_CHECK(result.name() == "SGN");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == 3);
BOOST_CHECK(result[0] == -1);
BOOST_CHECK(result[1] == 0);
BOOST_CHECK(result[2] == 1);
CHECK_EQ(result.name(), "SGN");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 3);
CHECK_EQ(result[0], -1);
CHECK_EQ(result[1], 0);
CHECK_EQ(result[2], 1);
result = SGN(-1);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == -1);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], -1);
result = SGN(0);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 0);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
result = SGN(1);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == 1);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 1);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_SGN_export ) {
TEST_CASE("test_SGN_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/SGN.xml";
@ -89,15 +82,13 @@ BOOST_AUTO_TEST_CASE( test_SGN_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]).epsilon(0.00001));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_SIN.cpp
*
* Copyright (c) 2019 hikyuu.org
*
*
* Created on: 2019-5-1
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/SIN.h>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_SIN ) {
TEST_CASE("test_SIN") {
Indicator result;
PriceList a;
@ -40,26 +34,25 @@ BOOST_AUTO_TEST_CASE( test_SIN ) {
Indicator data = PRICELIST(a);
result = SIN(data);
BOOST_CHECK(result.name() == "SIN");
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == std::sin(data[i]));
CHECK_EQ(result.name(), "SIN");
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], std::sin(data[i]));
}
result = SIN(-11);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == std::sin(-11));
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], std::sin(-11));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_SIN_export ) {
TEST_CASE("test_SIN_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/SIN.xml";
@ -80,16 +73,14 @@ BOOST_AUTO_TEST_CASE( test_SIN_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "SIN");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "SIN");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]).epsilon(0.00001));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,12 @@
* test_SMA.cpp
*
* Copyright (c) 2019 hikyuu.org
*
*
* Created on: 2019-5-16
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/SMA.h>
@ -29,69 +23,68 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_SMA ) {
TEST_CASE("test_SMA") {
Indicator result;
PriceList a;
Indicator data = PRICELIST(a);
/** @arg 输入指标长度为0 */
result = SMA(data);
BOOST_CHECK(result.name() == "SMA");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == 0);
CHECK_EQ(result.name(), "SMA");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 0);
/** @arg 输入指标长度为1n = 2, m=2 */
a.push_back(10);
data = PRICELIST(a);
result = SMA(data, 2, 2);
BOOST_CHECK(result.name() == "SMA");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result[0] == 10);
CHECK_EQ(result.name(), "SMA");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result[0], 10);
/** @arg 输入指标长度为1n = 1, m=2 */
a.clear();
a.push_back(10);
data = PRICELIST(a);
result = SMA(data, 1, 2);
BOOST_CHECK(result.name() == "SMA");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result[0] == 10);
CHECK_EQ(result.name(), "SMA");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result[0], 10);
/** @arg 输入指标长度为10n = 1, m=1 */
a.clear();
a.clear();
for (int i = 0; i < 10; ++i) {
a.push_back(i/10.0);
a.push_back(i / 10.0);
}
data = PRICELIST(a);
result = SMA(data, 1, 1);
BOOST_CHECK(result.name() == "SMA");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == data.size());
CHECK_EQ(result.name(), "SMA");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), data.size());
for (size_t i = result.discard(); i < data.size(); i++) {
BOOST_CHECK(result[i] == data[i]);
CHECK_EQ(result[i], data[i]);
}
/** @arg 输入指标长度为1n = 4, m=2 */
result = SMA(data, 4, 2);
BOOST_CHECK(result.name() == "SMA");
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result.size() == data.size());
BOOST_CHECK(result[0] == 0);
BOOST_CHECK(result[1] == 0.05);
BOOST_CHECK_CLOSE(result[5], 0.4031, 0.01);
BOOST_CHECK_CLOSE(result[9], 0.8002, 0.01);
CHECK_EQ(result.name(), "SMA");
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 0.05);
CHECK_EQ(result[5], doctest::Approx(0.4031).epsilon(0.01));
CHECK_EQ(result[9], doctest::Approx(0.8002).epsilon(0.01));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_SMA_export ) {
TEST_CASE("test_SMA_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/SMA.xml";
@ -112,16 +105,14 @@ BOOST_AUTO_TEST_CASE( test_SMA_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "SMA");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "SMA");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]).epsilon(0.00001));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -1,19 +1,13 @@
/*
* test_SQRT.cpp
*
*
* Copyright (c) 2019 hikyuu.org
*
* Created on: 2019-4-14
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/POW.h>
@ -30,7 +24,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_SQRT ) {
TEST_CASE("test_SQRT") {
Indicator result;
PriceList a;
@ -41,27 +35,26 @@ BOOST_AUTO_TEST_CASE( test_SQRT ) {
Indicator data = PRICELIST(a);
result = SQRT(data);
BOOST_CHECK(result.name() == "SQRT");
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == std::sqrt(data[i]));
CHECK_EQ(result.name(), "SQRT");
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], std::sqrt(data[i]));
}
result = SQRT(4);
BOOST_CHECK(result.name() == "SQRT");
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == std::sqrt(4));
CHECK_EQ(result.name(), "SQRT");
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], std::sqrt(4));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_SQRT_export ) {
TEST_CASE("test_SQRT_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/SQRT.xml";
@ -82,15 +75,13 @@ BOOST_AUTO_TEST_CASE( test_SQRT_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]).epsilon(0.00001));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/KDATA.h>
@ -27,11 +21,11 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_STDEV ) {
TEST_CASE("test_STDEV") {
/** @arg n > 1 的正常情况 */
PriceList d;
for (size_t i = 0; i < 15; ++i) {
d.push_back(i+1);
d.push_back(i + 1);
}
d[5] = 4.0;
d[7] = 4.0;
@ -39,40 +33,39 @@ BOOST_AUTO_TEST_CASE( test_STDEV ) {
Indicator ind = PRICELIST(d);
Indicator dev = STDEV(ind, 10);
BOOST_CHECK(dev.size() == 15);
BOOST_CHECK(std::isnan(dev[8]));
BOOST_CHECK(std::fabs(dev[9] - 2.923088) < 0.000001 );
BOOST_CHECK(std::fabs(dev[10] - 3.142893) < 0.000001 );
BOOST_CHECK(std::fabs(dev[11] - 2.830390) < 0.000001 );
BOOST_CHECK(std::fabs(dev[12] - 3.267686) < 0.000001 );
BOOST_CHECK(std::fabs(dev[13] - 3.653004) < 0.000001 );
BOOST_CHECK(std::fabs(dev[14] - 4.001388) < 0.000001 );
CHECK_EQ(dev.size(), 15);
CHECK_UNARY(std::isnan(dev[8]));
CHECK_LT(std::fabs(dev[9] - 2.923088), 0.000001);
CHECK_LT(std::fabs(dev[10] - 3.142893), 0.000001);
CHECK_LT(std::fabs(dev[11] - 2.830390), 0.000001);
CHECK_LT(std::fabs(dev[12] - 3.267686), 0.000001);
CHECK_LT(std::fabs(dev[13] - 3.653004), 0.000001);
CHECK_LT(std::fabs(dev[14] - 4.001388), 0.000001);
/** @arg n = 1时 */
dev = STDEV(ind, 1);
BOOST_CHECK(dev.size() == 15);
CHECK_EQ(dev.size(), 15);
for (size_t i = 0; i < dev.size(); ++i) {
BOOST_CHECK(std::isnan(dev[i]));
CHECK_UNARY(std::isnan(dev[i]));
}
/** @arg operator() */
Indicator expect = STDEV(ind, 10);
dev = STDEV(10);
Indicator result = dev(ind);
BOOST_CHECK(result.size() == expect.size());
CHECK_EQ(result.size(), expect.size());
for (size_t i = expect.discard(); i < expect.size(); ++i) {
BOOST_CHECK(result[i] == expect[i]);
CHECK_EQ(result[i], expect[i]);
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_STDEV_export ) {
TEST_CASE("test_STDEV_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/STDEV.xml";
@ -93,15 +86,13 @@ BOOST_AUTO_TEST_CASE( test_STDEV_export ) {
ia >> BOOST_SERIALIZATION_NVP(ma2);
}
BOOST_CHECK(ma1.size() == ma2.size());
BOOST_CHECK(ma1.discard() == ma2.discard());
BOOST_CHECK(ma1.getResultNumber() == ma2.getResultNumber());
CHECK_EQ(ma1.size(), ma2.size());
CHECK_EQ(ma1.discard(), ma2.discard());
CHECK_EQ(ma1.getResultNumber(), ma2.getResultNumber());
for (size_t i = ma1.discard(); i < ma1.size(); ++i) {
BOOST_CHECK_CLOSE(ma1[i], ma2[i], 0.00001);
CHECK_EQ(ma1[i], doctest::Approx(ma2[i]).epsilon(0.00001));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/KDATA.h>
@ -27,11 +21,11 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_STDP ) {
TEST_CASE("test_STDP") {
/** @arg n > 1 的正常情况 */
PriceList d;
for (size_t i = 0; i < 15; ++i) {
d.push_back(i+1);
d.push_back(i + 1);
}
d[5] = 4.0;
d[7] = 4.0;
@ -39,42 +33,41 @@ BOOST_AUTO_TEST_CASE( test_STDP ) {
Indicator ind = PRICELIST(d);
Indicator dev = STDP(ind, 10);
BOOST_CHECK(dev.name() == "STDP");
BOOST_CHECK(dev.size() == 15);
BOOST_CHECK(std::isnan(dev[8]));
BOOST_CHECK(std::fabs(dev[9] - 2.77308) < 0.00001 );
BOOST_CHECK(std::fabs(dev[10] - 2.98161) < 0.00001 );
BOOST_CHECK(std::fabs(dev[11] - 2.68514) < 0.00001 );
BOOST_CHECK(std::fabs(dev[12] - 3.1) < 0.00001 );
BOOST_CHECK(std::fabs(dev[13] - 3.46554) < 0.00001 );
BOOST_CHECK(std::fabs(dev[14] - 3.79605) < 0.00001 );
CHECK_EQ(dev.name(), "STDP");
CHECK_EQ(dev.size(), 15);
CHECK_UNARY(std::isnan(dev[8]));
CHECK_LT(std::fabs(dev[9] - 2.77308), 0.00001);
CHECK_LT(std::fabs(dev[10] - 2.98161), 0.00001);
CHECK_LT(std::fabs(dev[11] - 2.68514), 0.00001);
CHECK_LT(std::fabs(dev[12] - 3.1), 0.00001);
CHECK_LT(std::fabs(dev[13] - 3.46554), 0.00001);
CHECK_LT(std::fabs(dev[14] - 3.79605), 0.00001);
/** @arg n = 1时 */
dev = STDP(ind, 1);
BOOST_CHECK(dev.name() == "STDP");
BOOST_CHECK(dev.size() == 15);
CHECK_EQ(dev.name(), "STDP");
CHECK_EQ(dev.size(), 15);
for (size_t i = 0; i < dev.size(); ++i) {
BOOST_CHECK(std::isnan(dev[i]));
CHECK_UNARY(std::isnan(dev[i]));
}
/** @arg operator() */
Indicator expect = STDP(ind, 10);
dev = STDP(10);
Indicator result = dev(ind);
BOOST_CHECK(result.size() == expect.size());
CHECK_EQ(result.size(), expect.size());
for (size_t i = result.discard(); i < expect.size(); ++i) {
BOOST_CHECK(result[i] == expect[i]);
CHECK_EQ(result[i], expect[i]);
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_STDP_export ) {
TEST_CASE("test_STDP_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/STDP.xml";
@ -95,19 +88,17 @@ BOOST_AUTO_TEST_CASE( test_STDP_export ) {
ia >> BOOST_SERIALIZATION_NVP(ma2);
}
BOOST_CHECK(ma2.name() == "STDP");
BOOST_CHECK(ma1.size() == ma2.size());
BOOST_CHECK(ma1.discard() == ma2.discard());
BOOST_CHECK(ma1.getResultNumber() == ma2.getResultNumber());
CHECK_EQ(ma2.name(), "STDP");
CHECK_EQ(ma1.size(), ma2.size());
CHECK_EQ(ma1.discard(), ma2.discard());
CHECK_EQ(ma1.getResultNumber(), ma2.getResultNumber());
for (size_t i = 0; i < ma1.discard(); i++) {
BOOST_CHECK(std::isnan(ma2[i]));
CHECK_UNARY(std::isnan(ma2[i]));
}
for (size_t i = ma1.discard(); i < ma1.size(); ++i) {
BOOST_CHECK_CLOSE(ma1[i], ma2[i], 0.00001);
CHECK_EQ(ma1[i], doctest::Approx(ma2[i]).epsilon(0.00001));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/SUM.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_SUM ) {
TEST_CASE("test_SUM") {
Indicator result;
PriceList a;
@ -39,45 +33,44 @@ BOOST_AUTO_TEST_CASE( test_SUM ) {
/** @arg n = 0 */
result = SUM(data, 0);
BOOST_CHECK(result.name() == "SUM");
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.name(), "SUM");
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
price_t sum = 0;
for (int i = 0; i <10; ++i) {
for (int i = 0; i < 10; ++i) {
sum += data[i];
BOOST_CHECK(result[i] == sum);
CHECK_EQ(result[i], sum);
}
/** @arg n = 1 */
result = SUM(data, 1);
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.discard() == 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
BOOST_CHECK(result[i] == data[i]);
CHECK_EQ(result[i], data[i]);
}
/** @arg n = 9 */
result = SUM(data, 9);
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.discard() == 8);
BOOST_CHECK(result[8] == 36);
BOOST_CHECK(result[9] == 45);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 8);
CHECK_EQ(result[8], 36);
CHECK_EQ(result[9], 45);
/** @arg n = 10 */
result = SUM(data, 10);
BOOST_CHECK(result.size() == 10);
BOOST_CHECK(result.discard() == 9);
BOOST_CHECK(result[9] == 45);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 9);
CHECK_EQ(result[9], 45);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_SUM_export ) {
TEST_CASE("test_SUM_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/SUM.xml";
@ -98,15 +91,13 @@ BOOST_AUTO_TEST_CASE( test_SUM_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]).epsilon(0.00001));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -0,0 +1,198 @@
/*
* test_SUMBARS.cpp
*
* Copyright (c) 2019 hikyuu.org
*
* Created on: 2019-5-7
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include < fstream >
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/CVAL.h>
#include <hikyuu/indicator/crt/SUMBARS.h>
#include <hikyuu/indicator/crt/KDATA.h>
#include <hikyuu/indicator/crt/PRICELIST.h>
using namespace hku;
/**
* @defgroup test_indicator_SUMBARS test_indicator_SUMBARS
* @ingroup test_hikyuu_indicator_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_SUMBARS") {
Indicator result;
PriceList a;
for (int i = 0; i < 10; i++) {
a.push_back(i * 10);
}
Indicator data = PRICELIST(a);
result = SUMBARS(data, 10);
CHECK_EQ(result.name(), "SUMBARS");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 1);
CHECK_UNARY(std::isnan(result[0]));
CHECK_EQ(result[1], 0);
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 0);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 0);
CHECK_EQ(result[6], 0);
CHECK_EQ(result[7], 0);
CHECK_EQ(result[8], 0);
CHECK_EQ(result[9], 0);
result = SUMBARS(data, 15);
CHECK_EQ(result.name(), "SUMBARS");
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 2);
CHECK_UNARY(std::isnan(result[0]));
CHECK_UNARY(std::isnan(result[1]));
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 0);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 0);
CHECK_EQ(result[6], 0);
CHECK_EQ(result[7], 0);
CHECK_EQ(result[8], 0);
CHECK_EQ(result[9], 0);
result = SUMBARS(data, 90);
CHECK_EQ(result.name(), "SUMBARS");
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.size(), data.size());
CHECK_EQ(result.discard(), 4);
CHECK_UNARY(std::isnan(result[0]));
CHECK_UNARY(std::isnan(result[1]));
CHECK_UNARY(std::isnan(result[2]));
CHECK_UNARY(std::isnan(result[3]));
CHECK_EQ(result[4], 2);
CHECK_EQ(result[5], 1);
CHECK_EQ(result[6], 1);
CHECK_EQ(result[7], 1);
CHECK_EQ(result[8], 1);
CHECK_EQ(result[9], 0);
result = SUMBARS(data, 0);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result[1], 0);
CHECK_EQ(result[2], 0);
CHECK_EQ(result[3], 0);
CHECK_EQ(result[4], 0);
CHECK_EQ(result[5], 0);
CHECK_EQ(result[6], 0);
CHECK_EQ(result[7], 0);
CHECK_EQ(result[8], 0);
CHECK_EQ(result[9], 0);
result = SUMBARS(data, 170);
CHECK_EQ(result.discard(), 6);
CHECK_EQ(result.size(), 10);
for (size_t i = 0; i < result.discard(); i++) {
CHECK_UNARY(std::isnan(result[i]));
}
CHECK_EQ(result[6], 3);
CHECK_EQ(result[7], 2);
CHECK_EQ(result[8], 2);
CHECK_EQ(result[9], 1);
result = SUMBARS(data, 450);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 9);
for (size_t i = 0; i < result.discard(); i++) {
CHECK_UNARY(std::isnan(result[i]));
}
CHECK_EQ(result[9], 8);
result = SUMBARS(data, 451);
CHECK_EQ(result.size(), 10);
CHECK_EQ(result.discard(), 10);
for (size_t i = 0; i < result.discard(); i++) {
CHECK_UNARY(std::isnan(result[i]));
}
result = SUMBARS(CVAL(10), 451);
CHECK_EQ(result.discard(), 1);
CHECK_EQ(result.size(), 1);
CHECK_UNARY(std::isnan(result[0]));
result = SUMBARS(CVAL(10), 10);
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
a.clear();
a.push_back(10);
a.push_back(20);
data = PRICELIST(a);
result = SUMBARS(data, 20);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result.discard(), 1);
CHECK_UNARY(std::isnan(result[0]));
CHECK_EQ(result[1], 0);
result = SUMBARS(data, 0);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], 0);
CHECK_EQ(result[1], 0);
result = SUMBARS(data, 30);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result.discard(), 1);
CHECK_UNARY(std::isnan(result[0]));
CHECK_EQ(result[1], 1);
result = SUMBARS(data, 40);
CHECK_EQ(result.size(), 2);
CHECK_EQ(result.discard(), 2);
CHECK_UNARY(std::isnan(result[0]));
CHECK_UNARY(std::isnan(result[1]));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
TEST_CASE("test_SUMBARS_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/SUMBARS.xml";
Stock stock = sm.getStock("sh000001");
KData kdata = stock.getKData(KQuery(-20));
Indicator x1 = SUMBARS(CLOSE(kdata), 10000);
{
std::ofstream ofs(filename);
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP(x1);
}
Indicator x2;
{
std::ifstream ifs(filename);
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(x2);
}
CHECK_EQ(x2.name(), "SUMBARS");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = x1.discard(); i < x1.size(); ++i) {
CHECK_EQ(x1[i], doctest::Approx(x2[i]).epsilon(0.00001));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -2,18 +2,11 @@
* test_TAN.cpp
*
* Copyright (c) 2019 hikyuu.org
*
*
* Created on: 2019-5-1
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/TAN.h>
@ -29,7 +22,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_TAN ) {
TEST_CASE("test_TAN") {
Indicator result;
PriceList a;
@ -40,26 +33,25 @@ BOOST_AUTO_TEST_CASE( test_TAN ) {
Indicator data = PRICELIST(a);
result = TAN(data);
BOOST_CHECK(result.name() == "TAN");
BOOST_CHECK(result.discard() == 0);
for (int i = 0; i <10; ++i) {
BOOST_CHECK(result[i] == std::tan(data[i]));
CHECK_EQ(result.name(), "TAN");
CHECK_EQ(result.discard(), 0);
for (int i = 0; i < 10; ++i) {
CHECK_EQ(result[i], std::tan(data[i]));
}
result = TAN(-11);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result.discard() == 0);
BOOST_CHECK(result[0] == std::tan(-11));
CHECK_EQ(result.size(), 1);
CHECK_EQ(result.discard(), 0);
CHECK_EQ(result[0], std::tan(-11));
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_TAN_export ) {
TEST_CASE("test_TAN_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/TAN.xml";
@ -80,16 +72,14 @@ BOOST_AUTO_TEST_CASE( test_TAN_export ) {
ia >> BOOST_SERIALIZATION_NVP(x2);
}
BOOST_CHECK(x2.name() == "TAN");
BOOST_CHECK(x1.size() == x2.size());
BOOST_CHECK(x1.discard() == x2.discard());
BOOST_CHECK(x1.getResultNumber() == x2.getResultNumber());
CHECK_EQ(x2.name(), "TAN");
CHECK_EQ(x1.size(), x2.size());
CHECK_EQ(x1.discard(), x2.discard());
CHECK_EQ(x1.getResultNumber(), x2.getResultNumber());
for (size_t i = 0; i < x1.size(); ++i) {
BOOST_CHECK_CLOSE(x1[i], x2[i], 0.00001);
CHECK_EQ(x1[i], doctest::Approx(x2[i]).epsilon(0.00001));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -1,19 +1,13 @@
/*
* test_VAR.cpp
*
*
* Copyright (c) 2019 hikyuu.org
*
* Created on: 2013-4-18
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/KDATA.h>
@ -29,11 +23,11 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_VAR ) {
TEST_CASE("test_VAR") {
/** @arg n > 1 的正常情况 */
PriceList d;
for (size_t i = 0; i < 15; ++i) {
d.push_back(i+1);
d.push_back(i + 1);
}
d[5] = 4.0;
d[7] = 4.0;
@ -41,42 +35,41 @@ BOOST_AUTO_TEST_CASE( test_VAR ) {
Indicator ind = PRICELIST(d);
Indicator dev = VAR(ind, 10);
BOOST_CHECK(dev.name() == "VAR");
BOOST_CHECK(dev.size() == 15);
BOOST_CHECK(std::isnan(dev[8]));
BOOST_CHECK(std::fabs(dev[9] - 8.54444) < 0.00001 );
BOOST_CHECK(std::fabs(dev[10] - 9.87778) < 0.00001 );
BOOST_CHECK(std::fabs(dev[11] - 8.01111) < 0.00001 );
BOOST_CHECK(std::fabs(dev[12] - 10.6778) < 0.0001 );
BOOST_CHECK(std::fabs(dev[13] - 13.3444) < 0.0001 );
BOOST_CHECK(std::fabs(dev[14] - 16.0111) < 0.0001 );
CHECK_EQ(dev.name(), "VAR");
CHECK_EQ(dev.size(), 15);
CHECK_UNARY(std::isnan(dev[8]));
CHECK_LT(std::fabs(dev[9] - 8.54444), 0.00001);
CHECK_LT(std::fabs(dev[10] - 9.87778), 0.00001);
CHECK_LT(std::fabs(dev[11] - 8.01111), 0.00001);
CHECK_LT(std::fabs(dev[12] - 10.6778), 0.0001);
CHECK_LT(std::fabs(dev[13] - 13.3444), 0.0001);
CHECK_LT(std::fabs(dev[14] - 16.0111), 0.0001);
/** @arg n = 1时 */
dev = VAR(ind, 1);
BOOST_CHECK(dev.name() == "VAR");
BOOST_CHECK(dev.size() == 15);
CHECK_EQ(dev.name(), "VAR");
CHECK_EQ(dev.size(), 15);
for (size_t i = 0; i < dev.size(); ++i) {
BOOST_CHECK(std::isnan(dev[i]));
CHECK_UNARY(std::isnan(dev[i]));
}
/** @arg operator() */
Indicator expect = VAR(ind, 10);
dev = VAR(10);
Indicator result = dev(ind);
BOOST_CHECK(result.size() == expect.size());
CHECK_EQ(result.size(), expect.size());
for (size_t i = expect.discard(); i < expect.size(); ++i) {
BOOST_CHECK(result[i] == expect[i]);
CHECK_EQ(result[i], expect[i]);
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_VAR_export ) {
TEST_CASE("test_VAR_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/VAR.xml";
@ -97,16 +90,14 @@ BOOST_AUTO_TEST_CASE( test_VAR_export ) {
ia >> BOOST_SERIALIZATION_NVP(ma2);
}
BOOST_CHECK(ma2.name() == "VAR");
BOOST_CHECK(ma1.size() == ma2.size());
BOOST_CHECK(ma1.discard() == ma2.discard());
BOOST_CHECK(ma1.getResultNumber() == ma2.getResultNumber());
CHECK_EQ(ma2.name(), "VAR");
CHECK_EQ(ma1.size(), ma2.size());
CHECK_EQ(ma1.discard(), ma2.discard());
CHECK_EQ(ma1.getResultNumber(), ma2.getResultNumber());
for (size_t i = ma1.discard(); i < ma1.size(); ++i) {
BOOST_CHECK_CLOSE(ma1[i], ma2[i], 0.00001);
CHECK_EQ(ma1[i], doctest::Approx(ma2[i]).epsilon(0.00001));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -1,19 +1,13 @@
/*
* test_VARP.cpp
*
*
* Copyright (c) 2019 hikyuu.org
*
* Created on: 2013-4-18
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/KDATA.h>
@ -29,11 +23,11 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_VARP ) {
TEST_CASE("test_VARP") {
/** @arg n > 1 的正常情况 */
PriceList d;
for (size_t i = 0; i < 15; ++i) {
d.push_back(i+1);
d.push_back(i + 1);
}
d[5] = 4.0;
d[7] = 4.0;
@ -41,42 +35,41 @@ BOOST_AUTO_TEST_CASE( test_VARP ) {
Indicator ind = PRICELIST(d);
Indicator dev = VARP(ind, 10);
BOOST_CHECK(dev.name() == "VARP");
BOOST_CHECK(dev.size() == 15);
BOOST_CHECK(std::isnan(dev[8]));
BOOST_CHECK(std::fabs(dev[9] - 7.69) < 0.01 );
BOOST_CHECK(std::fabs(dev[10] - 8.89) < 0.01 );
BOOST_CHECK(std::fabs(dev[11] - 7.21) < 0.01 );
BOOST_CHECK(std::fabs(dev[12] - 9.61) < 0.01 );
BOOST_CHECK(std::fabs(dev[13] - 12.01) < 0.01 );
BOOST_CHECK(std::fabs(dev[14] - 14.41) < 0.01 );
CHECK_EQ(dev.name(), "VARP");
CHECK_EQ(dev.size(), 15);
CHECK_UNARY(std::isnan(dev[8]));
CHECK_LT(std::fabs(dev[9] - 7.69), 0.01);
CHECK_LT(std::fabs(dev[10] - 8.89), 0.01);
CHECK_LT(std::fabs(dev[11] - 7.21), 0.01);
CHECK_LT(std::fabs(dev[12] - 9.61), 0.01);
CHECK_LT(std::fabs(dev[13] - 12.01), 0.01);
CHECK_LT(std::fabs(dev[14] - 14.41), 0.01);
/** @arg n = 1时 */
dev = VARP(ind, 1);
BOOST_CHECK(dev.name() == "VARP");
BOOST_CHECK(dev.size() == 15);
CHECK_EQ(dev.name(), "VARP");
CHECK_EQ(dev.size(), 15);
for (size_t i = 0; i < dev.size(); ++i) {
BOOST_CHECK(std::isnan(dev[i]));
CHECK_UNARY(std::isnan(dev[i]));
}
/** @arg operator() */
Indicator expect = VARP(ind, 10);
dev = VARP(10);
Indicator result = dev(ind);
BOOST_CHECK(result.size() == expect.size());
CHECK_EQ(result.size(), expect.size());
for (size_t i = result.discard(); i < expect.size(); ++i) {
BOOST_CHECK(result[i] == expect[i]);
CHECK_EQ(result[i], expect[i]);
}
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_VARP_export ) {
TEST_CASE("test_VARP_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/VARP.xml";
@ -97,16 +90,14 @@ BOOST_AUTO_TEST_CASE( test_VARP_export ) {
ia >> BOOST_SERIALIZATION_NVP(ma2);
}
BOOST_CHECK(ma2.name() == "VARP");
BOOST_CHECK(ma1.size() == ma2.size());
BOOST_CHECK(ma1.discard() == ma2.discard());
BOOST_CHECK(ma1.getResultNumber() == ma2.getResultNumber());
CHECK_EQ(ma2.name(), "VARP");
CHECK_EQ(ma1.size(), ma2.size());
CHECK_EQ(ma1.discard(), ma2.discard());
CHECK_EQ(ma1.getResultNumber(), ma2.getResultNumber());
for (size_t i = ma1.discard(); i < ma1.size(); ++i) {
BOOST_CHECK_CLOSE(ma1[i], ma2[i], 0.00001);
CHECK_EQ(ma1[i], doctest::Approx(ma2[i]).epsilon(0.00001));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <hikyuu/StockManager.h>
#include <hikyuu/indicator/crt/VIGOR.h>
@ -25,7 +19,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_VIGOR ) {
TEST_CASE("test_VIGOR") {
StockManager& sm = StockManager::instance();
Stock stock = sm.getStock("sh600000");
KData kdata;
@ -33,32 +27,31 @@ BOOST_AUTO_TEST_CASE( test_VIGOR ) {
/** @arg kdata为空时 */
vigor = VIGOR(kdata, 1);
BOOST_CHECK(vigor.size() == 0);
BOOST_CHECK(vigor.empty() == true);
CHECK_EQ(vigor.size(), 0);
CHECK_EQ(vigor.empty(), true);
/** @arg 正常情况 */
KQuery query = KQuery(0, 10);
kdata = stock.getKData(query);
BOOST_CHECK(kdata.size() == 10);
CHECK_EQ(kdata.size(), 10);
vigor = VIGOR(kdata, 1);
BOOST_CHECK(vigor.discard() == 1);
BOOST_CHECK(vigor.size()== 10);
BOOST_CHECK(vigor.empty() == false);
BOOST_CHECK(std::isnan(vigor[0]));
BOOST_CHECK(std::fabs(vigor[1] + 11761.36) < 0.0001 );
CHECK_EQ(vigor.discard(), 1);
CHECK_EQ(vigor.size(), 10);
CHECK_UNARY_FALSE(vigor.empty());
CHECK_UNARY(std::isnan(vigor[0]));
CHECK_LT(std::fabs(vigor[1] + 11761.36), 0.0001);
vigor = VIGOR(kdata, 2);
BOOST_CHECK(vigor.discard() == 1);
CHECK_EQ(vigor.discard(), 1);
}
//-----------------------------------------------------------------------------
// test export
//-----------------------------------------------------------------------------
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_VIGOR_export ) {
TEST_CASE("test_VIGOR_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/VIGOR.xml";
@ -79,15 +72,13 @@ BOOST_AUTO_TEST_CASE( test_VIGOR_export ) {
ia >> BOOST_SERIALIZATION_NVP(ma2);
}
BOOST_CHECK(ma1.size() == ma2.size());
BOOST_CHECK(ma1.discard() == ma2.discard());
BOOST_CHECK(ma1.getResultNumber() == ma2.getResultNumber());
CHECK_EQ(ma1.size(), ma2.size());
CHECK_EQ(ma1.discard(), ma2.discard());
CHECK_EQ(ma1.getResultNumber(), ma2.getResultNumber());
for (size_t i = ma1.discard(); i < ma1.size(); ++i) {
BOOST_CHECK_CLOSE(ma1[i], ma2[i], 0.00001);
CHECK_EQ(ma1[i], doctest::Approx(ma2[i]).epsilon(0.00001));
}
}
#endif /* #if HKU_SUPPORT_SERIALIZATION */
/** @} */

View File

@ -1,17 +1,4 @@
/*
* test_export.cpp
*
* Created on: 2013-4-30
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_indicator_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <hikyuu/config.h>
#if HKU_SUPPORT_SERIALIZATION
@ -31,7 +18,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_WAEVE_export ) {
TEST_CASE("test_WAEVE_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/WEAVE.xml";
@ -54,20 +41,19 @@ BOOST_AUTO_TEST_CASE( test_WAEVE_export ) {
ia >> BOOST_SERIALIZATION_NVP(w2);
}
BOOST_CHECK(w1.size() == w2.size());
BOOST_CHECK(w1.discard() == w2.discard());
BOOST_CHECK(w1.getResultNumber() == 2);
BOOST_CHECK(w2.getResultNumber() == 2);
CHECK_EQ(w1.size(), w2.size());
CHECK_EQ(w1.discard(), w2.discard());
CHECK_EQ(w1.getResultNumber(), 2);
CHECK_EQ(w2.getResultNumber(), 2);
size_t total = w1.size();
for (size_t i = 0; i < total; ++i) {
BOOST_CHECK_CLOSE(w1[i], w2[i], 0.00001);
CHECK_EQ(w1[i], doctest::Approx(w2[i]).epsilon(0.00001));
}
for (size_t i = 0; i < total; ++i) {
BOOST_CHECK_CLOSE(w1.get(i,1), w2.get(i,1), 0.00001);
CHECK_EQ(w1.get(i, 1), doctest::Approx(w2.get(i, 1)).epsilon(0.00001));
}
}
/** @} */
#endif /* HKU_SUPPORT_SERIALIZATION */

View File

@ -4,14 +4,7 @@
* Created on: 201529
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_serialize_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
@ -29,7 +22,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_Block_serialize ) {
TEST_CASE("test_Block_serialize") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/Block.xml";
@ -48,9 +41,9 @@ BOOST_AUTO_TEST_CASE( test_Block_serialize ) {
ia >> BOOST_SERIALIZATION_NVP(blk2);
}
BOOST_CHECK(blk1.category() == blk2.category());
BOOST_CHECK(blk1.name() == blk2.name());
BOOST_CHECK(blk1.size() == blk2.size());
CHECK_EQ(blk1.category(), blk2.category());
CHECK_EQ(blk1.name(), blk2.name());
CHECK_EQ(blk1.size(), blk2.size());
blk1.add("sh000001");
blk1.add("sz000001");
@ -64,14 +57,13 @@ BOOST_AUTO_TEST_CASE( test_Block_serialize ) {
boost::archive::xml_iarchive ia(ifs);
ia >> BOOST_SERIALIZATION_NVP(blk2);
}
BOOST_CHECK(blk1.category() == blk2.category());
BOOST_CHECK(blk1.name() == blk2.name());
BOOST_CHECK(blk1.size() == blk2.size());
BOOST_CHECK(blk2.have("sh000001"));
BOOST_CHECK(blk2.have("sz000001"));
CHECK_EQ(blk1.category(), blk2.category());
CHECK_EQ(blk1.name(), blk2.name());
CHECK_EQ(blk1.size(), blk2.size());
CHECK_UNARY(blk2.have("sh000001"));
CHECK_UNARY(blk2.have("sz000001"));
}
/** @} */
#endif /* HKU_SUPPORT_SERIALIZATION */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_serialize_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_KData_serialize ) {
TEST_CASE("test_KData_serialize") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/KData.xml";
@ -50,17 +44,14 @@ BOOST_AUTO_TEST_CASE( test_KData_serialize ) {
ia >> BOOST_SERIALIZATION_NVP(k2);
}
BOOST_CHECK(k1.size() == k2.size());
BOOST_CHECK(k1.size() != 0);
CHECK_EQ(k1.size(), k2.size());
CHECK_NE(k1.size(), 0);
size_t total = k1.size();
for (size_t i = 0; i < total; ++i) {
BOOST_CHECK(k1[i] == k2[i]);
CHECK_EQ(k1[i], k2[i]);
}
}
/** @} */
#endif /* HKU_SUPPORT_SERIALIZATION */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_serialize_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
@ -30,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_KQuery_serialize ) {
TEST_CASE("test_KQuery_serialize") {
string filename(StockManager::instance().tmpdir());
filename += "/KQuery.xml";
@ -48,16 +41,15 @@ BOOST_AUTO_TEST_CASE( test_KQuery_serialize ) {
ia >> BOOST_SERIALIZATION_NVP(q2);
}
BOOST_CHECK(q1.queryType() == q1.queryType());
BOOST_CHECK(q1.kType() == q1.kType());
BOOST_CHECK(q1.recoverType() == q1.recoverType());
BOOST_CHECK(q1.start() == q1.start());
BOOST_CHECK(q1.end() == q1.end());
CHECK_EQ(q1.queryType(), q1.queryType());
CHECK_EQ(q1.kType(), q1.kType());
CHECK_EQ(q1.recoverType(), q1.recoverType());
CHECK_EQ(q1.start(), q1.start());
CHECK_EQ(q1.end(), q1.end());
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_KQueryByDate_serialize ) {
TEST_CASE("test_KQueryByDate_serialize") {
string filename(StockManager::instance().tmpdir());
filename += "/KQueryByDate.xml";
@ -76,11 +68,11 @@ BOOST_AUTO_TEST_CASE( test_KQueryByDate_serialize ) {
ia >> BOOST_SERIALIZATION_NVP(q2);
}
BOOST_CHECK(q1.queryType() == q1.queryType());
BOOST_CHECK(q1.kType() == q1.kType());
BOOST_CHECK(q1.recoverType() == q1.recoverType());
BOOST_CHECK(q1.startDatetime() == q1.startDatetime());
BOOST_CHECK(q1.endDatetime() == q1.endDatetime());
CHECK_EQ(q1.queryType(), q1.queryType());
CHECK_EQ(q1.kType(), q1.kType());
CHECK_EQ(q1.recoverType(), q1.recoverType());
CHECK_EQ(q1.startDatetime(), q1.startDatetime());
CHECK_EQ(q1.endDatetime(), q1.endDatetime());
/* KQueryByDate读取 */
KQuery q3 = KQueryByDate(Datetime(200101010000), Datetime(200102100000));
@ -97,11 +89,11 @@ BOOST_AUTO_TEST_CASE( test_KQueryByDate_serialize ) {
ia >> BOOST_SERIALIZATION_NVP(q4);
}
BOOST_CHECK(q3.queryType() == q4.queryType());
BOOST_CHECK(q3.kType() == q4.kType());
BOOST_CHECK(q3.recoverType() == q4.recoverType());
BOOST_CHECK(q3.startDatetime() == q4.startDatetime());
BOOST_CHECK(q3.endDatetime() == q4.endDatetime());
CHECK_EQ(q3.queryType(), q4.queryType());
CHECK_EQ(q3.kType(), q4.kType());
CHECK_EQ(q3.recoverType(), q4.recoverType());
CHECK_EQ(q3.startDatetime(), q4.startDatetime());
CHECK_EQ(q3.endDatetime(), q4.endDatetime());
}
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_serialize_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_KRecord_serialize ) {
TEST_CASE("test_KRecord_serialize") {
string filename(StockManager::instance().tmpdir());
filename += "/KRecord.xml";
@ -47,18 +41,15 @@ BOOST_AUTO_TEST_CASE( test_KRecord_serialize ) {
ia >> BOOST_SERIALIZATION_NVP(k2);
}
BOOST_CHECK(k1.datetime == k2.datetime);
BOOST_CHECK(k1.openPrice == k2.openPrice);
BOOST_CHECK(k1.highPrice == k2.highPrice);
BOOST_CHECK(k1.lowPrice == k2.lowPrice);
BOOST_CHECK(k1.closePrice == k2.closePrice);
BOOST_CHECK(k1.datetime == k2.datetime);
BOOST_CHECK(k1.datetime == k2.datetime);
CHECK_EQ(k1.datetime, k2.datetime);
CHECK_EQ(k1.openPrice, k2.openPrice);
CHECK_EQ(k1.highPrice, k2.highPrice);
CHECK_EQ(k1.lowPrice, k2.lowPrice);
CHECK_EQ(k1.closePrice, k2.closePrice);
CHECK_EQ(k1.datetime, k2.datetime);
CHECK_EQ(k1.datetime, k2.datetime);
}
/** @} */
#endif /* HKU_SUPPORT_SERIALIZATION */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_serialize_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_MarketInfo_serialize ) {
TEST_CASE("test_MarketInfo_serialize") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/MarketInfo.xml";
@ -48,17 +42,13 @@ BOOST_AUTO_TEST_CASE( test_MarketInfo_serialize ) {
ia >> BOOST_SERIALIZATION_NVP(m2);
}
BOOST_CHECK(m1.market() == m2.market());
BOOST_CHECK(m1.name() == m2.name());
BOOST_CHECK(m1.description() == m2.description());
BOOST_CHECK(m1.code() == m2.code());
BOOST_CHECK(m1.lastDate() == m2.lastDate());
CHECK_EQ(m1.market(), m2.market());
CHECK_EQ(m1.name(), m2.name());
CHECK_EQ(m1.description(), m2.description());
CHECK_EQ(m1.code(), m2.code());
CHECK_EQ(m1.lastDate(), m2.lastDate());
}
/** @} */
#endif /* HKU_SUPPORT_SERIALIZATION */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_serialize_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_StockTypeInfo_serialize ) {
TEST_CASE("test_StockTypeInfo_serialize") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/StockTypeInfo.xml";
@ -48,19 +42,16 @@ BOOST_AUTO_TEST_CASE( test_StockTypeInfo_serialize ) {
ia >> BOOST_SERIALIZATION_NVP(m2);
}
BOOST_CHECK(m1.type() == m2.type());
BOOST_CHECK(m1.description() == m2.description());
BOOST_CHECK(m1.tick() == m2.tick());
BOOST_CHECK(m1.tickValue() == m2.tickValue());
BOOST_CHECK(m1.unit() == m2.unit());
BOOST_CHECK(m1.precision() == m2.precision());
BOOST_CHECK(m1.minTradeNumber() == m2.minTradeNumber());
BOOST_CHECK(m1.maxTradeNumber() == m2.maxTradeNumber());
CHECK_EQ(m1.type(), m2.type());
CHECK_EQ(m1.description(), m2.description());
CHECK_EQ(m1.tick(), m2.tick());
CHECK_EQ(m1.tickValue(), m2.tickValue());
CHECK_EQ(m1.unit(), m2.unit());
CHECK_EQ(m1.precision(), m2.precision());
CHECK_EQ(m1.minTradeNumber(), m2.minTradeNumber());
CHECK_EQ(m1.maxTradeNumber(), m2.maxTradeNumber());
}
/** @} */
#endif /* HKU_SUPPORT_SERIALIZATION */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_serialize_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
@ -29,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_StockWeight_serialize ) {
TEST_CASE("test_StockWeight_serialize") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/StockWeight.xml";
@ -49,24 +43,21 @@ BOOST_AUTO_TEST_CASE( test_StockWeight_serialize ) {
ia >> BOOST_SERIALIZATION_NVP(weight_list_2);
}
BOOST_CHECK(weight_list_1.size() == weight_list_2.size());
BOOST_CHECK(weight_list_1.size() != 0);
CHECK_EQ(weight_list_1.size(), weight_list_2.size());
CHECK_NE(weight_list_1.size(), 0);
size_t total = weight_list_2.size();
for (size_t i = 0; i < total; ++i) {
BOOST_CHECK(weight_list_1[i].datetime() == weight_list_2[i].datetime());
BOOST_CHECK(weight_list_1[i].countAsGift() == weight_list_2[i].countAsGift());
BOOST_CHECK(weight_list_1[i].countForSell() == weight_list_2[i].countForSell());
BOOST_CHECK(weight_list_1[i].priceForSell() == weight_list_2[i].priceForSell());
BOOST_CHECK(weight_list_1[i].bonus() == weight_list_2[i].bonus());
BOOST_CHECK(weight_list_1[i].increasement() == weight_list_2[i].increasement());
BOOST_CHECK(weight_list_1[i].totalCount() == weight_list_2[i].totalCount());
BOOST_CHECK(weight_list_1[i].freeCount() == weight_list_2[i].freeCount());
CHECK_EQ(weight_list_1[i].datetime(), weight_list_2[i].datetime());
CHECK_EQ(weight_list_1[i].countAsGift(), weight_list_2[i].countAsGift());
CHECK_EQ(weight_list_1[i].countForSell(), weight_list_2[i].countForSell());
CHECK_EQ(weight_list_1[i].priceForSell(), weight_list_2[i].priceForSell());
CHECK_EQ(weight_list_1[i].bonus(), weight_list_2[i].bonus());
CHECK_EQ(weight_list_1[i].increasement(), weight_list_2[i].increasement());
CHECK_EQ(weight_list_1[i].totalCount(), weight_list_2[i].totalCount());
CHECK_EQ(weight_list_1[i].freeCount(), weight_list_2[i].freeCount());
}
}
/** @} */
#endif /* HKU_SUPPORT_SERIALIZATION */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_serialize_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
@ -30,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_TimeLineRecord_serialize ) {
TEST_CASE("test_TimeLineRecord_serialize") {
string filename(StockManager::instance().tmpdir());
filename += "/TimeLineRecord.xml";
@ -48,14 +41,13 @@ BOOST_AUTO_TEST_CASE( test_TimeLineRecord_serialize ) {
ia >> BOOST_SERIALIZATION_NVP(t2);
}
BOOST_CHECK(t1.datetime == t2.datetime);
BOOST_CHECK(t1.price == t2.price);
BOOST_CHECK(t1.vol == t2.vol);
CHECK_EQ(t1.datetime, t2.datetime);
CHECK_EQ(t1.price, t2.price);
CHECK_EQ(t1.vol, t2.vol);
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_TimeLineList_serialize ) {
TEST_CASE("test_TimeLineList_serialize") {
string filename(StockManager::instance().tmpdir());
filename += "/TimeLineList.xml";
@ -76,17 +68,14 @@ BOOST_AUTO_TEST_CASE( test_TimeLineList_serialize ) {
ia >> BOOST_SERIALIZATION_NVP(line2);
}
BOOST_CHECK(line1.size() != 0);
BOOST_CHECK(line1.size() == line2.size());
CHECK_NE(line1.size(), 0);
CHECK_EQ(line1.size(), line2.size());
size_t total = line1.size();
for (size_t i = 0; i < total; i++) {
BOOST_CHECK(line1[i] == line2[i]);
CHECK_EQ(line1[i], line2[i]);
}
}
/** @} */
#endif /* HKU_SUPPORT_SERIALIZATION */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_serialize_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <fstream>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
@ -30,7 +23,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_TransRecord_serialize ) {
TEST_CASE("test_TransRecord_serialize") {
string filename(StockManager::instance().tmpdir());
filename += "/TransRecord.xml";
@ -48,12 +41,11 @@ BOOST_AUTO_TEST_CASE( test_TransRecord_serialize ) {
ia >> BOOST_SERIALIZATION_NVP(t2);
}
BOOST_CHECK(t1 == t2);
CHECK_EQ(t1, t2);
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_TransList_serialize ) {
TEST_CASE("test_TransList_serialize") {
string filename(StockManager::instance().tmpdir());
filename += "/TransList.xml";
@ -74,17 +66,14 @@ BOOST_AUTO_TEST_CASE( test_TransList_serialize ) {
ia >> BOOST_SERIALIZATION_NVP(line2);
}
BOOST_CHECK(line1.size() != 0);
BOOST_CHECK(line1.size() == line2.size());
CHECK_NE(line1.size(), 0);
CHECK_EQ(line1.size(), line2.size());
size_t total = line1.size();
for (size_t i = 0; i < total; i++) {
BOOST_CHECK(line1[i] == line2[i]);
CHECK_EQ(line1[i], line2[i]);
}
}
/** @} */
#endif /* HKU_SUPPORT_SERIALIZATION */

View File

@ -0,0 +1,74 @@
/*
* Copyright(C) hikyuu.org
*
* Created on: 2010-5-26
* Author: fasiondog
*/
#define DOCTEST_CONFIG_IMPLEMENT
#include "doctest/doctest.h"
#include <filesystem>
#include <hikyuu/hikyuu.h>
using namespace std::filesystem;
using namespace hku;
void init_hikyuu_test() {
path current = current_path();
if (current.stem() == path("test")) {
current /= path("data");
} else {
current /= "test_data";
}
std::cout << "current path : " << current << std::endl;
#if defined(_MSC_VER)
std::cout << "configure file: " << current.string() << "\\hikyuu_win.ini" << std::endl;
hku::hikyuu_init(current.string() + "\\hikyuu_win.ini");
#else
std::cout << "configure file: " << current.string() << "/hikyuu_linux.ini" << std::endl;
hikyuu_init(current.string() + "/hikyuu_linux.ini");
#endif
path tmp_dir = current;
tmp_dir /= "tmp";
if (!exists(tmp_dir)) {
create_directory(tmp_dir);
}
}
int main(int argc, char** argv) {
doctest::Context context;
// !!! THIS IS JUST AN EXAMPLE SHOWING HOW DEFAULTS/OVERRIDES ARE SET !!!
// defaults
// context.addFilter("test-case-exclude", "*math*"); // exclude test cases with "math" in their name
context.setOption("abort-after", 5); // stop test execution after 5 failed assertions
context.setOption("order-by", "name"); // sort the test cases by their name
context.applyCommandLine(argc, argv);
// overrides
context.setOption("no-breaks", true); // don't break in the debugger when assertions fail
init_hikyuu_test();
int res = 0;
{
SPEND_TIME_MSG(total_test_run, utf8_to_gb("测试总耗时"));
res = context.run(); // run
std::cout << std::endl;
}
std::cout << std::endl;
if (context.shouldExit()) // important - query flags (and --exit) rely on the user doing this
return res; // propagate the result of the tests
int client_stuff_return_code = 0;
// your program - if the testing framework is integrated in your production code
return res + client_stuff_return_code; // the result from doctest is propagated here as well
}

File diff suppressed because it is too large Load Diff

View File

@ -4,14 +4,7 @@
* Created on: 2013-2-14
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_trade_manage_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
#include <hikyuu/trade_manage/crt/TC_FixedA.h>
@ -31,7 +24,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_TC_FixedA ) {
TEST_CASE("test_TC_FixedA") {
StockManager& sm = StockManager::instance();
Stock stock;
CostRecord result, expect;
@ -39,9 +32,9 @@ BOOST_AUTO_TEST_CASE( test_TC_FixedA ) {
/** @arg Stock is Null */
result = cost_func->getBuyCost(Datetime(200101010000), stock, 10.0, 100);
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
result = cost_func->getSellCost(Datetime(200101010000), stock, 10.0, 1000);
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
/** @arg 买入沪市股票少于1000股佣金少于5元 */
stock = sm.getStock("sh600004");
@ -50,7 +43,7 @@ BOOST_AUTO_TEST_CASE( test_TC_FixedA ) {
expect.stamptax = 0.0;
expect.transferfee = 1.0;
expect.total = 6.0;
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
/** @arg 买入沪市股票等于1000股佣金大于5元 */
result = cost_func->getBuyCost(Datetime(200101010000), stock, 10.0, 1000);
@ -58,7 +51,7 @@ BOOST_AUTO_TEST_CASE( test_TC_FixedA ) {
expect.stamptax = 0.0;
expect.transferfee = 1.0;
expect.total = 19.0;
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
/** @arg 买入沪市股票大于1000股佣金大于5元 */
result = cost_func->getBuyCost(Datetime(200101010000), stock, 10.0, 2100);
@ -66,7 +59,7 @@ BOOST_AUTO_TEST_CASE( test_TC_FixedA ) {
expect.stamptax = 0.0;
expect.transferfee = 2.1;
expect.total = 39.9;
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
/** @arg 卖出沪市股票少于1000股佣金少于5元 */
stock = sm.getStock("sh600004");
@ -75,7 +68,7 @@ BOOST_AUTO_TEST_CASE( test_TC_FixedA ) {
expect.stamptax = 1.0;
expect.transferfee = 1.0;
expect.total = 7.0;
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
/** @arg 卖出沪市股票等于1000股佣金大于5元 */
result = cost_func->getSellCost(Datetime(200101010000), stock, 10.0, 1000);
@ -83,7 +76,7 @@ BOOST_AUTO_TEST_CASE( test_TC_FixedA ) {
expect.stamptax = 10.0;
expect.transferfee = 1.0;
expect.total = 29.0;
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
/** @arg 卖出沪市股票大于1000股佣金大于5元 */
result = cost_func->getSellCost(Datetime(200101010000), stock, 10.0, 2100);
@ -91,7 +84,7 @@ BOOST_AUTO_TEST_CASE( test_TC_FixedA ) {
expect.stamptax = 21;
expect.transferfee = 2.1;
expect.total = 60.9;
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
/** @arg 买入深市股票少于1000股佣金少于5元 */
stock = sm.getStock("sz000001");
@ -100,7 +93,7 @@ BOOST_AUTO_TEST_CASE( test_TC_FixedA ) {
expect.stamptax = 0.0;
expect.transferfee = 0.0;
expect.total = 5.0;
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
/** @arg 买入深市股票等于1000股佣金大于5元 */
result = cost_func->getBuyCost(Datetime(200101010000), stock, 10.0, 1000);
@ -108,7 +101,7 @@ BOOST_AUTO_TEST_CASE( test_TC_FixedA ) {
expect.stamptax = 0.0;
expect.transferfee = 0.0;
expect.total = 18.0;
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
/** @arg 买入深市股票大于1000股佣金大于5元 */
result = cost_func->getBuyCost(Datetime(200101010000), stock, 10.0, 2100);
@ -116,7 +109,7 @@ BOOST_AUTO_TEST_CASE( test_TC_FixedA ) {
expect.stamptax = 0.0;
expect.transferfee = 0.0;
expect.total = 37.8;
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
/** @arg 卖出深市股票少于1000股佣金少于5元 */
result = cost_func->getSellCost(Datetime(200101010000), stock, 10.0, 100);
@ -124,7 +117,7 @@ BOOST_AUTO_TEST_CASE( test_TC_FixedA ) {
expect.stamptax = 1.0;
expect.transferfee = 0.0;
expect.total = 6.0;
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
/** @arg 卖出深市股票等于1000股佣金大于5元 */
result = cost_func->getSellCost(Datetime(200101010000), stock, 10.0, 1000);
@ -132,7 +125,7 @@ BOOST_AUTO_TEST_CASE( test_TC_FixedA ) {
expect.stamptax = 10.0;
expect.transferfee = 0.0;
expect.total = 28.0;
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
/** @arg 卖出深市股票大于1000股佣金大于5元 */
result = cost_func->getSellCost(Datetime(200101010000), stock, 10.0, 2100);
@ -140,13 +133,12 @@ BOOST_AUTO_TEST_CASE( test_TC_FixedA ) {
expect.stamptax = 21;
expect.transferfee = 0.0;
expect.total = 58.8;
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
}
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_FixedATC_export ) {
TEST_CASE("test_FixedATC_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
@ -166,7 +158,7 @@ BOOST_AUTO_TEST_CASE( test_FixedATC_export ) {
ia >> BOOST_SERIALIZATION_NVP(func2);
}
BOOST_CHECK(func2->name() == "FixedATradeCost");
CHECK_EQ(func2->name(), "FixedATradeCost");
CostRecord result, expect;
Stock stock = sm.getStock("sh600004");
@ -175,14 +167,14 @@ BOOST_AUTO_TEST_CASE( test_FixedATC_export ) {
expect.stamptax = 0.0;
expect.transferfee = 1.0;
expect.total = 6.0;
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
result = func2->getBuyCost(Datetime(200101010000), stock, 10.0, 1000);
expect.commission = 18.0;
expect.stamptax = 0.0;
expect.transferfee = 1.0;
expect.total = 19.0;
BOOST_CHECK(result == expect);
CHECK_EQ(result, expect);
}
#endif /* HKU_SUPPORT_SERIALIZATION */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_trade_manage_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
#include <hikyuu/trade_manage/crt/TC_Zero.h>
@ -31,36 +25,35 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_TC_Zero ) {
TEST_CASE("test_TC_Zero") {
StockManager& sm = StockManager::instance();
Stock stock = sm.getStock("sh600004");
TradeCostPtr cost_func = TC_Zero();
CostRecord result;
/** @arg 检查name */
BOOST_CHECK(cost_func->name() == "TC_Zero");
CHECK_EQ(cost_func->name(), "TC_Zero");
/** @arg 计算买入成本 */
result = cost_func->getBuyCost(Datetime(200101010000), stock, 9.01, 1000);
BOOST_CHECK(result == Null<CostRecord>());
CHECK_EQ(result, Null<CostRecord>());
/** @arg 计算卖出成本 */
result = cost_func->getSellCost(Datetime(200101010000), stock, 9.01, 1000);
BOOST_CHECK(result == Null<CostRecord>());
CHECK_EQ(result, Null<CostRecord>());
/** @arg 测试clone */
TradeCostPtr cost_clone_func = cost_func->clone();
BOOST_CHECK(cost_clone_func->name() == "TC_Zero");
CHECK_EQ(cost_clone_func->name(), "TC_Zero");
result = cost_clone_func->getBuyCost(Datetime(200101010000), stock, 9.01, 1000);
BOOST_CHECK(result == Null<CostRecord>());
CHECK_EQ(result, Null<CostRecord>());
result = cost_clone_func->getSellCost(Datetime(200101010000), stock, 9.01, 1000);
BOOST_CHECK(result == Null<CostRecord>());
CHECK_EQ(result, Null<CostRecord>());
}
#if HKU_SUPPORT_SERIALIZATION
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_ZeroCost_export ) {
TEST_CASE("test_ZeroCost_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
@ -83,11 +76,11 @@ BOOST_AUTO_TEST_CASE( test_ZeroCost_export ) {
Stock stock = sm.getStock("sh600004");
CostRecord result;
BOOST_CHECK(zero2->name() == "TC_Zero");
CHECK_EQ(zero2->name(), "TC_Zero");
result = zero2->getBuyCost(Datetime(200101010000), stock, 9.01, 1000);
BOOST_CHECK(result == Null<CostRecord>());
CHECK_EQ(result, Null<CostRecord>());
result = zero2->getSellCost(Datetime(200101010000), stock, 9.01, 1000);
BOOST_CHECK(result == Null<CostRecord>());
CHECK_EQ(result, Null<CostRecord>());
}
#endif /* HKU_SUPPORT_SERIALIZATION */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_trade_manage_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <hikyuu/config.h>
#include <fstream>
@ -33,7 +27,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_CostRecord_export ) {
TEST_CASE("test_CostRecord_export") {
string filename(StockManager::instance().tmpdir());
filename += "/CostRecord.xml";
@ -51,17 +45,16 @@ BOOST_AUTO_TEST_CASE( test_CostRecord_export ) {
ia >> BOOST_SERIALIZATION_NVP(cost2);
}
BOOST_CHECK(cost == cost2);
BOOST_CHECK_CLOSE(cost.commission, cost2.commission, 0.00001);
BOOST_CHECK_CLOSE(cost.stamptax, cost2.stamptax, 0.00001);
BOOST_CHECK_CLOSE(cost.transferfee, cost2.transferfee, 0.00001);
BOOST_CHECK_CLOSE(cost.others, cost2.others, 0.00001);
BOOST_CHECK_CLOSE(cost.total, cost2.total, 0.00001);
CHECK_EQ(cost, cost2);
CHECK_EQ(cost.commission, doctest::Approx(cost2.commission).epsilon(0.00001));
CHECK_EQ(cost.stamptax, doctest::Approx(cost2.stamptax).epsilon(0.00001));
CHECK_EQ(cost.transferfee, doctest::Approx(cost2.transferfee).epsilon(0.00001));
CHECK_EQ(cost.others, doctest::Approx(cost2.others).epsilon(0.00001));
CHECK_EQ(cost.total, doctest::Approx(cost2.total).epsilon(0.00001));
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_TradeRecord_export ) {
TEST_CASE("test_TradeRecord_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/TradeRecord.xml";
@ -92,12 +85,11 @@ BOOST_AUTO_TEST_CASE( test_TradeRecord_export ) {
ia >> BOOST_SERIALIZATION_NVP(record2);
}
BOOST_CHECK(record1 == record2);
CHECK_EQ(record1, record2);
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_PositionRecord_export ) {
TEST_CASE("test_PositionRecord_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/PositionRecord.xml";
@ -129,12 +121,11 @@ BOOST_AUTO_TEST_CASE( test_PositionRecord_export ) {
ia >> BOOST_SERIALIZATION_NVP(record2);
}
BOOST_CHECK(record1 == record2);
CHECK_EQ(record1, record2);
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_TradeManager_export ) {
TEST_CASE("test_TradeManager_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/TradeManager.xml";
@ -157,42 +148,41 @@ BOOST_AUTO_TEST_CASE( test_TradeManager_export ) {
ia >> BOOST_SERIALIZATION_NVP(tm2);
}
BOOST_CHECK(tm1->name() == tm2->name());
BOOST_CHECK(tm1->initCash() == tm2->initCash());
BOOST_CHECK(tm1->initDatetime() == tm2->initDatetime());
BOOST_CHECK(tm1->firstDatetime() == tm2->firstDatetime());
BOOST_CHECK(tm1->lastDatetime() == tm2->lastDatetime());
BOOST_CHECK(tm1->reinvest() == tm2->reinvest());
BOOST_CHECK(tm1->precision() == tm2->precision());
CHECK_EQ(tm1->name(), tm2->name());
CHECK_EQ(tm1->initCash(), tm2->initCash());
CHECK_EQ(tm1->initDatetime(), tm2->initDatetime());
CHECK_EQ(tm1->firstDatetime(), tm2->firstDatetime());
CHECK_EQ(tm1->lastDatetime(), tm2->lastDatetime());
CHECK_EQ(tm1->reinvest(), tm2->reinvest());
CHECK_EQ(tm1->precision(), tm2->precision());
const TradeRecordList& trade_list_1 = tm1->getTradeList();
const TradeRecordList& trade_list_2 = tm2->getTradeList();
BOOST_CHECK(trade_list_1.size() == trade_list_2.size());
CHECK_EQ(trade_list_1.size(), trade_list_2.size());
size_t total = trade_list_1.size();
for (size_t i = 0; i < total; i++) {
BOOST_CHECK(trade_list_1[i] == trade_list_2[i]);
CHECK_EQ(trade_list_1[i], trade_list_2[i]);
}
PositionRecordList position1 = tm1->getPositionList();
PositionRecordList position2 = tm2->getPositionList();
BOOST_CHECK(position1.size() == position2.size());
CHECK_EQ(position1.size(), position2.size());
total = position1.size();
for (size_t i = 0; i < total; ++i) {
BOOST_CHECK(position1[i] == position2[i]);
CHECK_EQ(position1[i], position2[i]);
}
position1 = tm1->getHistoryPositionList();
position2 = tm2->getHistoryPositionList();
BOOST_CHECK(position1.size() == position2.size());
CHECK_EQ(position1.size(), position2.size());
total = position1.size();
for (size_t i = 0; i < total; ++i) {
BOOST_CHECK(position1[i] == position2[i]);
CHECK_EQ(position1[i], position2[i]);
}
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_FundsRecord_export ) {
TEST_CASE("test_FundsRecord_export") {
string filename(StockManager::instance().tmpdir());
filename += "/FundsRecord.xml";
@ -217,12 +207,11 @@ BOOST_AUTO_TEST_CASE( test_FundsRecord_export ) {
ia >> BOOST_SERIALIZATION_NVP(funds2);
}
BOOST_CHECK(funds1 == funds2);
CHECK_EQ(funds1, funds2);
}
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_BorrowRecord_export ) {
TEST_CASE("test_BorrowRecord_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/BorrowRecord.xml";
@ -245,14 +234,11 @@ BOOST_AUTO_TEST_CASE( test_BorrowRecord_export ) {
ia >> BOOST_SERIALIZATION_NVP(bor2);
}
BOOST_CHECK(bor1.stock == bor2.stock);
BOOST_CHECK(bor1.number == bor2.number);
BOOST_CHECK(bor1.value == bor2.value);
CHECK_EQ(bor1.stock, bor2.stock);
CHECK_EQ(bor1.number, bor2.number);
CHECK_EQ(bor1.value, bor2.value);
}
/** @} */
#endif /* HKU_SUPPORT_SERIALIZATION */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_trade_sys_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
#include <hikyuu/trade_manage/crt/crtTM.h>
#include <hikyuu/trade_sys/system/crt/SYS_Simple.h>
@ -28,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点,不自动调仓 */
BOOST_AUTO_TEST_CASE( test_AF_EqualWeight_not_adjust_hold) {
TEST_CASE("test_AF_EqualWeight_not_adjust_hold") {
StockManager& sm = StockManager::instance();
SEPtr se = SE_Fixed();
@ -53,19 +46,19 @@ BOOST_AUTO_TEST_CASE( test_AF_EqualWeight_not_adjust_hold) {
sys->setTM(subtm->clone());
se->addStock(sm["sh600000"], sys);
se_list = se->getSelectedSystemList(Datetime(201802100000L));
BOOST_CHECK(se_list.size() == 1);
BOOST_CHECK(hold_list.size() == 0);
BOOST_CHECK(se_list[0]->getTM()->currentCash() == 0);
CHECK_EQ(se_list.size(), 1);
CHECK_EQ(hold_list.size(), 0);
CHECK_EQ(se_list[0]->getTM()->currentCash(), 0);
sw_list = af->_allocateWeight(Datetime(201802100000L), se_list);
ac_list = af->getAllocatedSystemList(Datetime(201802100000L), se_list, hold_list);
BOOST_CHECK(sw_list.size() == 1);
BOOST_CHECK(sw_list[0].getSYS()->getStock() == sm["sh600000"]);
BOOST_CHECK(sw_list[0].getWeight() == 1);
BOOST_CHECK(se_list[0]->getTM()->currentCash() == 100000);
BOOST_CHECK(tm->currentCash() == 0);
BOOST_CHECK(ac_list.size() == 1);
BOOST_CHECK(ac_list[0] == sw_list[0].getSYS());
CHECK_EQ(sw_list.size(), 1);
CHECK_EQ(sw_list[0].getSYS()->getStock(), sm["sh600000"]);
CHECK_EQ(sw_list[0].getWeight(), 1);
CHECK_EQ(se_list[0]->getTM()->currentCash(), 100000);
CHECK_EQ(tm->currentCash(), 0);
CHECK_EQ(ac_list.size(), 1);
CHECK_EQ(ac_list[0], sw_list[0].getSYS());
/** @arg 当前选中系统数大于最大持仓系统数已持仓系统数为0 */
af->setParam<int>("max_sys_num", 1);
@ -75,22 +68,22 @@ BOOST_AUTO_TEST_CASE( test_AF_EqualWeight_not_adjust_hold) {
se->addStock(sm["sh600000"], sys);
se->addStock(sm["sh600004"], sys);
se_list = se->getSelectedSystemList(Datetime(201802100000L));
BOOST_CHECK(se_list.size() > af->getParam<int>("max_sys_num"));
BOOST_CHECK(hold_list.size() == 0);
BOOST_CHECK(se_list[0]->getTM()->currentCash() == 0);
BOOST_CHECK(se_list[1]->getTM()->currentCash() == 0);
BOOST_CHECK(tm->currentCash() == 100000);
CHECK_GT(se_list.size(), af->getParam<int>("max_sys_num"));
CHECK_EQ(hold_list.size(), 0);
CHECK_EQ(se_list[0]->getTM()->currentCash(), 0);
CHECK_EQ(se_list[1]->getTM()->currentCash(), 0);
CHECK_EQ(tm->currentCash(), 100000);
sw_list = af->_allocateWeight(Datetime(201802100000L), se_list);
ac_list = af->getAllocatedSystemList(Datetime(201802100000L), se_list, hold_list);
BOOST_CHECK(sw_list.size() == 2);
BOOST_CHECK(sw_list[0].getSYS()->getStock() == sm["sh600000"]);
BOOST_CHECK(sw_list[0].getWeight() == 1);
BOOST_CHECK(se_list[0]->getTM()->currentCash() == 0);
BOOST_CHECK(tm->currentCash() == 0);
BOOST_CHECK(ac_list.size() == 1);
BOOST_CHECK(ac_list[0] == sw_list[1].getSYS());
BOOST_CHECK(ac_list[0]->getTM()->currentCash() == 100000);
CHECK_EQ(sw_list.size(), 2);
CHECK_EQ(sw_list[0].getSYS()->getStock(), sm["sh600000"]);
CHECK_EQ(sw_list[0].getWeight(), 1);
CHECK_EQ(se_list[0]->getTM()->currentCash(), 0);
CHECK_EQ(tm->currentCash(), 0);
CHECK_EQ(ac_list.size(), 1);
CHECK_EQ(ac_list[0], sw_list[1].getSYS());
CHECK_EQ(ac_list[0]->getTM()->currentCash(), 100000);
/** @arg 当前选中系统数不为0已持仓系统数等于最大持仓数 */
af->setParam<int>("max_sys_num", 2);
@ -103,22 +96,22 @@ BOOST_AUTO_TEST_CASE( test_AF_EqualWeight_not_adjust_hold) {
se->addStock(sm["sh600004"], sys);
se->addStock(sm["sz000001"], sys);
hold_list = se->getSelectedSystemList(Datetime(201802100000L));
BOOST_CHECK(se_list.size() != 0);
BOOST_CHECK(hold_list.size() == af->getParam<int>("max_sys_num"));
BOOST_CHECK(tm->currentCash() == 100000);
CHECK_NE(se_list.size(), 0);
CHECK_EQ(hold_list.size(), af->getParam<int>("max_sys_num"));
CHECK_EQ(tm->currentCash(), 100000);
sw_list = af->_allocateWeight(Datetime(201802100000L), se_list);
ac_list = af->getAllocatedSystemList(Datetime(201802100000L), se_list, hold_list);
BOOST_CHECK(sw_list.size() == 1);
BOOST_CHECK(sw_list[0].getSYS()->getStock() == sm["sh600000"]);
BOOST_CHECK(sw_list[0].getWeight() == 1);
BOOST_CHECK(se_list[0]->getTM()->currentCash() == 0);
BOOST_CHECK(tm->currentCash() == 100000);
BOOST_CHECK(ac_list.size() == 2);
BOOST_CHECK(ac_list[0]->getStock() == sm["sh600004"]);
BOOST_CHECK(ac_list[1]->getStock() == sm["sz000001"]);
BOOST_CHECK(ac_list[0]->getTM()->currentCash() == 0);
BOOST_CHECK(ac_list[1]->getTM()->currentCash() == 0);
CHECK_EQ(sw_list.size(), 1);
CHECK_EQ(sw_list[0].getSYS()->getStock(), sm["sh600000"]);
CHECK_EQ(sw_list[0].getWeight(), 1);
CHECK_EQ(se_list[0]->getTM()->currentCash(), 0);
CHECK_EQ(tm->currentCash(), 100000);
CHECK_EQ(ac_list.size(), 2);
CHECK_EQ(ac_list[0]->getStock(), sm["sh600004"]);
CHECK_EQ(ac_list[1]->getStock(), sm["sz000001"]);
CHECK_EQ(ac_list[0]->getTM()->currentCash(), 0);
CHECK_EQ(ac_list[1]->getTM()->currentCash(), 0);
/** @arg 当前选中系统数不为0已持仓系统数大于最大持仓数 */
af->setParam<int>("max_sys_num", 1);
@ -131,24 +124,24 @@ BOOST_AUTO_TEST_CASE( test_AF_EqualWeight_not_adjust_hold) {
se->addStock(sm["sh600004"], sys);
se->addStock(sm["sz000001"], sys);
hold_list = se->getSelectedSystemList(Datetime(201802100000L));
BOOST_CHECK(se_list.size() != 0);
BOOST_CHECK(hold_list.size() > af->getParam<int>("max_sys_num"));
BOOST_CHECK(tm->currentCash() == 100000);
BOOST_CHECK(hold_list[0]->getTM()->currentCash() == 0);
BOOST_CHECK(hold_list[1]->getTM()->currentCash() == 0);
CHECK_NE(se_list.size(), 0);
CHECK_GT(hold_list.size(), af->getParam<int>("max_sys_num"));
CHECK_EQ(tm->currentCash(), 100000);
CHECK_EQ(hold_list[0]->getTM()->currentCash(), 0);
CHECK_EQ(hold_list[1]->getTM()->currentCash(), 0);
sw_list = af->_allocateWeight(Datetime(201802100000L), se_list);
ac_list = af->getAllocatedSystemList(Datetime(201802100000L), se_list, hold_list);
BOOST_CHECK(sw_list.size() == 1);
BOOST_CHECK(sw_list[0].getSYS()->getStock() == sm["sh600000"]);
BOOST_CHECK(sw_list[0].getWeight() == 1);
BOOST_CHECK(se_list[0]->getTM()->currentCash() == 0);
BOOST_CHECK(tm->currentCash() == 100000);
BOOST_CHECK(ac_list.size() == 2);
BOOST_CHECK(ac_list[0]->getStock() == sm["sh600004"]);
BOOST_CHECK(ac_list[1]->getStock() == sm["sz000001"]);
BOOST_CHECK(ac_list[0]->getTM()->currentCash() == 0);
BOOST_CHECK(ac_list[1]->getTM()->currentCash() == 0);
CHECK_EQ(sw_list.size(), 1);
CHECK_EQ(sw_list[0].getSYS()->getStock(), sm["sh600000"]);
CHECK_EQ(sw_list[0].getWeight(), 1);
CHECK_EQ(se_list[0]->getTM()->currentCash(), 0);
CHECK_EQ(tm->currentCash(), 100000);
CHECK_EQ(ac_list.size(), 2);
CHECK_EQ(ac_list[0]->getStock(), sm["sh600004"]);
CHECK_EQ(ac_list[1]->getStock(), sm["sz000001"]);
CHECK_EQ(ac_list[0]->getTM()->currentCash(), 0);
CHECK_EQ(ac_list[1]->getTM()->currentCash(), 0);
/** @arg 当前选中系统数不为0且不包含持仓系统持仓系统数不为零且小于最大持仓数 */
af->setParam<int>("max_sys_num", 4);
@ -165,28 +158,28 @@ BOOST_AUTO_TEST_CASE( test_AF_EqualWeight_not_adjust_hold) {
se->addStock(sm["sh600004"], sys);
se->addStock(sm["sz000001"], sys);
hold_list = se->getSelectedSystemList(Datetime(201802100000L));
BOOST_CHECK(se_list.size() != 0);
BOOST_CHECK(hold_list.size() < af->getParam<int>("max_sys_num"));
BOOST_CHECK(tm->currentCash() == 100000);
BOOST_CHECK(hold_list[0]->getTM()->currentCash() == 0);
BOOST_CHECK(hold_list[1]->getTM()->currentCash() == 0);
CHECK_NE(se_list.size(), 0);
CHECK_LT(hold_list.size(), af->getParam<int>("max_sys_num"));
CHECK_EQ(tm->currentCash(), 100000);
CHECK_EQ(hold_list[0]->getTM()->currentCash(), 0);
CHECK_EQ(hold_list[1]->getTM()->currentCash(), 0);
sw_list = af->_allocateWeight(Datetime(201802100000L), se_list);
ac_list = af->getAllocatedSystemList(Datetime(201802100000L), se_list, hold_list);
BOOST_CHECK(sw_list.size() == 5);
BOOST_CHECK(tm->currentCash() == 0);
BOOST_CHECK(ac_list.size() == 4);
CHECK_EQ(sw_list.size(), 5);
CHECK_EQ(tm->currentCash(), 0);
CHECK_EQ(ac_list.size(), 4);
std::set<Stock> stk_set;
for (auto iter = ac_list.begin(); iter != ac_list.end(); ++iter) {
stk_set.insert((*iter)->getStock());
}
BOOST_CHECK(stk_set.find(sm["sh600004"]) != stk_set.end());
BOOST_CHECK(stk_set.find(sm["sz000001"]) != stk_set.end());
BOOST_CHECK(ac_list[0] == hold_list[0]);
BOOST_CHECK(ac_list[1] == hold_list[1]);
BOOST_CHECK(ac_list[0]->getTM()->currentCash() == 0);
BOOST_CHECK(ac_list[1]->getTM()->currentCash() == 0);
CHECK_NE(stk_set.find(sm["sh600004"]), stk_set.end());
CHECK_NE(stk_set.find(sm["sz000001"]), stk_set.end());
CHECK_EQ(ac_list[0], hold_list[0]);
CHECK_EQ(ac_list[1], hold_list[1]);
CHECK_EQ(ac_list[0]->getTM()->currentCash(), 0);
CHECK_EQ(ac_list[1]->getTM()->currentCash(), 0);
/*
std::cout << "current cash: " << tm->currentCash() << std::endl;
@ -209,15 +202,9 @@ BOOST_AUTO_TEST_CASE( test_AF_EqualWeight_not_adjust_hold) {
*/
}
/** @par 检测点,自动调仓 */
//BOOST_AUTO_TEST_CASE( test_AF_EqualWeight_adjust_hold) {
//TODO test_AF_EqualWeight_adjust_hold
// TEST_CASE( test_AF_EqualWeight_adjust_hold) {
// TODO test_AF_EqualWeight_adjust_hold
//}
/** @} */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_trade_sys_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
#include <hikyuu/trade_manage/crt/crtTM.h>
#include <hikyuu/trade_sys/system/crt/SYS_Simple.h>
@ -28,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_AllocateFunds) {
TEST_CASE("test_AllocateFunds") {
StockManager& sm = StockManager::instance();
SEPtr se = SE_Fixed();
@ -43,23 +36,23 @@ BOOST_AUTO_TEST_CASE( test_AllocateFunds) {
SystemWeightList sw_list;
/** @arg 测试setTM */
BOOST_CHECK(!af->getTM());
CHECK_UNARY(!af->getTM());
af->setTM(tm);
BOOST_CHECK(af->getTM());
CHECK_UNARY(af->getTM());
/** @arg 测试clone */
AFPtr af2 = af->clone();
BOOST_CHECK(af2.get() != af.get());
BOOST_CHECK(af2->name() == af->name());
BOOST_CHECK(af2->getTM() == af->getTM());
CHECK_NE(af2.get(), af.get());
CHECK_EQ(af2->name(), af->name());
CHECK_EQ(af2->getTM(), af->getTM());
/** @arg 出入的se_list、hold_list均为空 */
BOOST_CHECK(se_list.size() == 0);
BOOST_CHECK(hold_list.size() == 0);
CHECK_EQ(se_list.size(), 0);
CHECK_EQ(hold_list.size(), 0);
sw_list = af->_allocateWeight(Datetime(201802100000L), se_list);
ac_list = af->getAllocatedSystemList(Datetime(201802100000L), se_list, hold_list);
BOOST_CHECK(sw_list.size() == 0);
BOOST_CHECK(ac_list.size() == 0);
CHECK_EQ(sw_list.size(), 0);
CHECK_EQ(ac_list.size(), 0);
/** @arg 最大持仓系统数小于0 */
af->setParam<int>("max_sys_num", -1);
@ -68,15 +61,14 @@ BOOST_AUTO_TEST_CASE( test_AllocateFunds) {
sys->setTM(subtm->clone());
se->addStock(sm["sh600000"], sys);
se_list = se->getSelectedSystemList(Datetime(201802100000L));
BOOST_CHECK(se_list.size() == 1);
CHECK_EQ(se_list.size(), 1);
sw_list = af->_allocateWeight(Datetime(201802100000L), se_list);
ac_list = af->getAllocatedSystemList(Datetime(201802100000L), se_list, se_list);
BOOST_CHECK(sw_list.size() == 1);
BOOST_CHECK(sw_list[0].getSYS() == se_list[0]);
BOOST_CHECK(ac_list.size() == 0);
BOOST_CHECK(tm->currentCash() == 100000);
CHECK_EQ(sw_list.size(), 1);
CHECK_EQ(sw_list[0].getSYS(), se_list[0]);
CHECK_EQ(ac_list.size(), 0);
CHECK_EQ(tm->currentCash(), 100000);
/** @arg 最大持仓系统数为0 */
af->setParam<int>("max_sys_num", 0);
@ -85,18 +77,13 @@ BOOST_AUTO_TEST_CASE( test_AllocateFunds) {
sys->setTM(subtm->clone());
se->addStock(sm["sh600000"], sys);
se_list = se->getSelectedSystemList(Datetime(201802100000L));
BOOST_CHECK(se_list.size() == 1);
CHECK_EQ(se_list.size(), 1);
sw_list = af->_allocateWeight(Datetime(201802100000L), se_list);
ac_list = af->getAllocatedSystemList(Datetime(201802100000L), se_list, hold_list);
BOOST_CHECK(sw_list.size() == 1);
BOOST_CHECK(ac_list.size() == 0);
BOOST_CHECK(tm->currentCash() == 100000);
CHECK_EQ(sw_list.size(), 1);
CHECK_EQ(ac_list.size(), 0);
CHECK_EQ(tm->currentCash(), 100000);
}
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_trade_sys_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <hikyuu/config.h>
#if HKU_SUPPORT_SERIALIZATION
@ -31,7 +25,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_AF_EqualWeight_export ) {
TEST_CASE("test_AF_EqualWeight_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/AF_EQUALWEIGHT.xml";
@ -50,14 +44,9 @@ BOOST_AUTO_TEST_CASE( test_AF_EqualWeight_export ) {
ia >> BOOST_SERIALIZATION_NVP(af2);
}
BOOST_CHECK(af1->name() == af2->name());
CHECK_EQ(af1->name(), af2->name());
}
/** @} */
#endif /* HKU_SUPPORT_SERIALIZATION */

View File

@ -5,21 +5,15 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_trade_sys_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
#include <hikyuu/trade_sys/condition/ConditionBase.h>
using namespace hku;
class ConditionTest: public ConditionBase {
class ConditionTest : public ConditionBase {
public:
ConditionTest(): ConditionBase("TEST") {
ConditionTest() : ConditionBase("TEST") {
setParam<int>("n", 10);
m_flag = false;
}
@ -40,14 +34,13 @@ public:
}
virtual ConditionPtr _clone() {
ConditionTest* p = new ConditionTest;
ConditionTest *p = new ConditionTest;
p->m_flag = m_flag;
return ConditionPtr(p);
}
private:
bool m_flag;
};
/**
@ -57,8 +50,8 @@ private:
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_Condition ) {
StockManager& sm = StockManager::instance();
TEST_CASE("test_Condition") {
StockManager &sm = StockManager::instance();
Stock stock = sm.getStock("sh000001");
KQuery query(0, 10);
KData kdata = stock.getKData(query);
@ -67,37 +60,34 @@ BOOST_AUTO_TEST_CASE( test_Condition ) {
/** @arg 基本操作 */
ConditionPtr p(new ConditionTest);
p_src = (ConditionTest *)p.get();
BOOST_CHECK(p_src->getKData().getStock() == Null<Stock>());
CHECK_EQ(p_src->getKData().getStock(), Null<Stock>());
p->setTO(kdata);
BOOST_CHECK(p_src->getKData().getStock() == stock);
CHECK_EQ(p_src->getKData().getStock(), stock);
p->reset();
BOOST_CHECK(p->name() == "TEST");
BOOST_CHECK(p->getParam<int>("n") == 10);
BOOST_CHECK(p->isValid(Datetime(200001010000)) == false);
CHECK_EQ(p->name(), "TEST");
CHECK_EQ(p->getParam<int>("n"), 10);
CHECK_EQ(p->isValid(Datetime(200001010000)), false);
p->reset();
//BOOST_CHECK(p->isValid(Datetime(200001010000)) == true);
// CHECK_EQ(p->isValid(Datetime(200001010000)) == true);
/** @arg 克隆操作 */
p->setParam<int>("n", 20);
ConditionPtr p_clone = p->clone();
BOOST_CHECK(p != p_clone);
CHECK_NE(p, p_clone);
p_src = (ConditionTest *)p_clone.get();
BOOST_CHECK(p_src->getKData().getStock() == stock);
CHECK_EQ(p_src->getKData().getStock(), stock);
p->setParam<int>("n", 30);
BOOST_CHECK(p->getParam<int>("n") == 30);
CHECK_EQ(p->getParam<int>("n"), 30);
p->reset();
BOOST_CHECK(p->isValid(Datetime(200001010000)) == false);
CHECK_EQ(p->isValid(Datetime(200001010000)), false);
BOOST_CHECK(p_clone->name() == "TEST");
BOOST_CHECK(p_clone->getParam<int>("n") == 20);
//BOOST_CHECK(p_clone->isValid(Datetime(200001010000)) == true);
CHECK_EQ(p_clone->name(), "TEST");
CHECK_EQ(p_clone->getParam<int>("n"), 20);
// CHECK_EQ(p_clone->isValid(Datetime(200001010000)) , true);
p_clone->reset();
BOOST_CHECK(p_clone->isValid(Datetime(200001010000)) == false);
CHECK_EQ(p_clone->isValid(Datetime(200001010000)), false);
}
/** @} */

View File

@ -0,0 +1,60 @@
/*
* test_Environment.cpp
*
* Created on: 2013-3-10
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
#include <hikyuu/trade_sys/environment/EnvironmentBase.h>
using namespace hku;
class EnvironmentTest : public EnvironmentBase {
public:
EnvironmentTest() : EnvironmentBase("TEST") {
setParam<int>("n", 10);
}
virtual ~EnvironmentTest() {}
virtual void _calculate() {
_addValid(Datetime(200001010000LL));
}
virtual EnvironmentPtr _clone() {
return make_shared<EnvironmentTest>();
}
};
/**
* @defgroup test_Environment test_Environment
* @ingroup test_hikyuu_trade_sys_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_Environment") {
/** @arg 基本操作 */
EnvironmentPtr p = make_shared<EnvironmentTest>();
CHECK_EQ(p->name(), "TEST");
CHECK_EQ(p->isValid(Datetime(200001010000)), false);
CHECK_EQ(p->isValid(Datetime(200001020000)), false);
p->setQuery(KQuery(-100));
CHECK_EQ(p->isValid(Datetime(200001010000)), true);
CHECK_EQ(p->isValid(Datetime(200001020000)), false);
CHECK_EQ(p->getParam<int>("n"), 10);
/** @arg 克隆操作 */
p->setParam<int>("n", 20);
EnvironmentPtr p_clone = p->clone();
CHECK_NE(p, p_clone);
CHECK_EQ(p_clone->name(), "TEST");
CHECK_EQ(p_clone->isValid(Datetime(200001010000)), true);
CHECK_EQ(p_clone->isValid(Datetime(200001020000)), false);
CHECK_EQ(p_clone->getParam<int>("n"), 20);
}
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_trade_sys_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
#include <hikyuu/trade_manage/crt/crtTM.h>
#include <hikyuu/trade_manage/crt/TC_FixedA.h>
@ -26,7 +20,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_MM_FixedCount ) {
TEST_CASE("test_MM_FixedCount") {
StockManager& sm = StockManager::instance();
Stock stock = sm.getStock("sh600000");
TradeManagerPtr tm = crtTM(Datetime(199001010000LL), 0.0, TC_FixedA());
@ -35,18 +29,16 @@ BOOST_AUTO_TEST_CASE( test_MM_FixedCount ) {
MoneyManagerPtr mm = MM_FixedCount(0);
mm->setTM(tm);
int result = mm->getBuyNumber(Datetime(200101010000), stock, 10.0, 10.0, PART_SIGNAL);
BOOST_CHECK(result == 0);
CHECK_EQ(result, 0);
/** @arg n = 100, 一个初始资金为0的交易账户能够执行买入操作 */
tm = crtTM(Datetime(199001010000LL), 0.0, TC_FixedA());
BOOST_CHECK(tm->initCash() == 0.0);
CHECK_EQ(tm->initCash(), 0.0);
mm = MM_FixedCount(100);
mm->setTM(tm);
mm->setParam<bool>("auto-checkin", true);
mm->getBuyNumber(Datetime(200001200000), stock, 24.11, 24.11, PART_SIGNAL);
BOOST_CHECK(tm->cash(Datetime(200001200000)) == 2417.02);
CHECK_EQ(tm->cash(Datetime(200001200000)), 2417.02);
}
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_trade_sys_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
#include <hikyuu/trade_manage/crt/crtTM.h>
#include <hikyuu/trade_manage/crt/TC_Zero.h>
@ -27,7 +21,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_MM_Nothing ) {
TEST_CASE("test_MM_Nothing") {
StockManager& sm = StockManager::instance();
Stock stock = sm.getStock("sh600000");
TradeManagerPtr tm;
@ -38,7 +32,7 @@ BOOST_AUTO_TEST_CASE( test_MM_Nothing ) {
MoneyManagerPtr mm = MM_Nothing();
mm->setTM(tm);
result = mm->getBuyNumber(Datetime(200101010000), stock, 10.0, 10.0, PART_SIGNAL);
BOOST_CHECK(result == 0);
CHECK_EQ(result, 0);
/** @arg 初始资金1292零成本算法不自动存入资金 */
tm = crtTM(Datetime(199001010000LL), 1292, TC_Zero());
@ -46,7 +40,7 @@ BOOST_AUTO_TEST_CASE( test_MM_Nothing ) {
mm->setTM(tm);
mm->setParam<bool>("auto-checkin", false);
result = mm->getBuyNumber(Datetime(200304160000), stock, 12.92, 12.92, PART_SIGNAL);
BOOST_CHECK(result == 100);
CHECK_EQ(result, 100);
/** @arg 初始资金1292固定成本算法不自动存入资金 */
tm = crtTM(Datetime(199001010000LL), 1292, TC_FixedA());
@ -54,31 +48,31 @@ BOOST_AUTO_TEST_CASE( test_MM_Nothing ) {
mm->setTM(tm);
mm->setParam<bool>("auto-checkin", false);
result = mm->getBuyNumber(Datetime(200304160000), stock, 12.92, 12.92, PART_SIGNAL);
BOOST_CHECK(result == 0);
CHECK_EQ(result, 0);
/** @arg 初始资金1292*2零成本算法不自动存入资金 */
tm = crtTM(Datetime(199001010000LL), 1292*2, TC_Zero());
tm = crtTM(Datetime(199001010000LL), 1292 * 2, TC_Zero());
mm = MM_Nothing();
mm->setTM(tm);
mm->setParam<bool>("auto-checkin", false);
result = mm->getBuyNumber(Datetime(200304160000), stock, 12.92, 12.92, PART_SIGNAL);
BOOST_CHECK(result == 200);
CHECK_EQ(result, 200);
/** @arg 初始资金1292*2固定成本算法不自动存入资金 */
tm = crtTM(Datetime(199001010000LL), 1292*2, TC_FixedA());
tm = crtTM(Datetime(199001010000LL), 1292 * 2, TC_FixedA());
mm = MM_Nothing();
mm->setTM(tm);
mm->setParam<bool>("auto-checkin", false);
result = mm->getBuyNumber(Datetime(200304160000), stock, 12.92, 12.92, PART_SIGNAL);
BOOST_CHECK(result == 100);
CHECK_EQ(result, 100);
/** @arg 初始资金1292*2固定成本算法自动存入资金 */
tm = crtTM(Datetime(199001010000LL), 1292*2, TC_FixedA());
tm = crtTM(Datetime(199001010000LL), 1292 * 2, TC_FixedA());
mm = MM_Nothing();
mm->setTM(tm);
mm->setParam<bool>("auto-checkin", true);
result = mm->getBuyNumber(Datetime(200304160000), stock, 12.92, 12.92, PART_SIGNAL);
BOOST_CHECK(result == 200);
CHECK_EQ(result, 200);
/** @arg 初始资金可买数超过最大可买数,零成本,不自动存入资金 */
tm = crtTM(Datetime(199001010000LL), 12.92 * 2000000LL, TC_Zero());
@ -86,7 +80,7 @@ BOOST_AUTO_TEST_CASE( test_MM_Nothing ) {
mm->setTM(tm);
mm->setParam<bool>("auto-checkin", false);
result = mm->getBuyNumber(Datetime(200304160000), stock, 12.92, 12.92, PART_SIGNAL);
BOOST_CHECK(result == 1000000L);
CHECK_EQ(result, 1000000L);
/** @arg 初始资金可买数超过最大可买数,零成本,自动存入资金 */
tm = crtTM(Datetime(199001010000LL), 12.92 * 2000000LL, TC_Zero());
@ -94,9 +88,7 @@ BOOST_AUTO_TEST_CASE( test_MM_Nothing ) {
mm->setTM(tm);
mm->setParam<bool>("auto-checkin", true);
result = mm->getBuyNumber(Datetime(200304160000), stock, 12.92, 12.92, PART_SIGNAL);
BOOST_CHECK(result == 1000000L);
CHECK_EQ(result, 1000000L);
}
/** @} */

View File

@ -0,0 +1,88 @@
/*
* test_MoneyManager.cpp
*
* Created on: 2013-3-11
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
#include <hikyuu/trade_manage/crt/crtTM.h>
#include <hikyuu/trade_sys/moneymanager/MoneyManagerBase.h>
using namespace hku;
class MoneyManagerTest : public MoneyManagerBase {
public:
MoneyManagerTest() : MoneyManagerBase("MoneyManagerTest") {
m_x = 0;
}
virtual ~MoneyManagerTest() {}
TradeManagerPtr getTM() const {
return m_tm;
}
int getX() const {
return m_x;
}
void setX(int x) {
m_x = x;
}
virtual size_t _getBuyNumber(const Datetime &datetime, const Stock &stock, price_t price, price_t risk,
SystemPart from) {
return 0;
}
virtual void _reset() {
m_x = 0;
}
virtual MoneyManagerPtr _clone() {
MoneyManagerTest *p = new MoneyManagerTest;
p->m_x = m_x;
return MoneyManagerPtr(p);
}
private:
int m_x;
};
/**
* @defgroup test_MoneyManager test_MoneyManager
* @ingroup test_hikyuu_trade_sys_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_MoneyManager") {
StockManager &sm = StockManager::instance();
Stock stock = sm["sh000001"];
TradeManagerPtr tm = crtTM();
/** @arg 基本操作 */
MoneyManagerPtr p(new MoneyManagerTest);
MoneyManagerTest *p_src = (MoneyManagerTest *)p.get();
CHECK_EQ(p->name(), "MoneyManagerTest");
CHECK_EQ(p_src->getTM(), TradeManagerPtr());
p->setTM(tm);
CHECK_EQ(p_src->getTM(), tm);
CHECK_EQ(p->getBuyNumber(Datetime(200001010000), stock, 10.0, 10.0, PART_SIGNAL), 0);
CHECK_UNARY((p->getSellNumber(Datetime(200001010000), stock, 10.0, 10.0, PART_SIGNAL) == Null<size_t>()));
CHECK_EQ(p_src->getX(), 0);
p_src->setX(10);
CHECK_EQ(p_src->getX(), 10);
p->reset();
CHECK_EQ(p_src->getX(), 0);
/** @arg 克隆操作 */
p_src->setX(10);
MoneyManagerPtr p_clone = p->clone();
CHECK_NE(p, p_clone);
p_src = (MoneyManagerTest *)p_clone.get();
CHECK_EQ(p->name(), "MoneyManagerTest");
// CHECK_EQ(p_src->getTM() == tm);
CHECK_EQ(p_src->getX(), 10);
}
/** @} */

View File

@ -5,13 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_trade_sys_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <hikyuu/config.h>
#if HKU_SUPPORT_SERIALIZATION
@ -31,7 +25,7 @@ using namespace hku;
*/
/** @par 检测点 */
BOOST_AUTO_TEST_CASE( test_MM_FixedCount_export ) {
TEST_CASE("test_MM_FixedCount_export") {
StockManager& sm = StockManager::instance();
string filename(sm.tmpdir());
filename += "/Fixed_MM.xml";
@ -50,14 +44,9 @@ BOOST_AUTO_TEST_CASE( test_MM_FixedCount_export ) {
ia >> BOOST_SERIALIZATION_NVP(mm2);
}
BOOST_CHECK(mm1->name() == mm2->name());
CHECK_EQ(mm1->name(), mm2->name());
}
/** @} */
#endif /* HKU_SUPPORT_SERIALIZATION */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_trade_sys_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
#include <hikyuu/trade_sys/portfolio/crt/PF_Simple.h>
@ -25,16 +18,14 @@ using namespace hku;
*/
/** @par 检测点 Portfolio基础操作 */
BOOST_AUTO_TEST_CASE( test_PF_for_base) {
TEST_CASE("test_PF_for_base") {
PortfolioPtr pf = PF_Simple();
BOOST_CHECK(pf->name() == "Portfolio");
CHECK_EQ(pf->name(), "Portfolio");
/** @arg 克隆操作 */
PFPtr pf2 = pf->clone();
BOOST_CHECK(pf2.get() != pf.get());
BOOST_CHECK(pf2->name() == pf->name());
CHECK_NE(pf2.get(), pf.get());
CHECK_EQ(pf2->name(), pf->name());
}
/** @} */

View File

@ -5,14 +5,7 @@
* Author: fasiondog
*/
#ifdef TEST_ALL_IN_ONE
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_MODULE test_hikyuu_trade_sys_suite
#include <boost/test/unit_test.hpp>
#endif
#include "doctest/doctest.h"
#include <hikyuu/StockManager.h>
#include <hikyuu/trade_manage/crt/crtTM.h>
#include <hikyuu/trade_sys/portfolio/crt/PF_Simple.h>
@ -24,7 +17,6 @@
#include <hikyuu/trade_sys/moneymanager/crt/MM_FixedCount.h>
#include <hikyuu/indicator/crt/EMA.h>
using namespace hku;
/**
@ -34,10 +26,9 @@ using namespace hku;
*/
/** @par 检测点 全部为delay模式系统实例不调整持仓*/
BOOST_AUTO_TEST_CASE( test_PF_for_delay_and_no_adjust) {
TEST_CASE("test_PF_for_delay_and_no_adjust") {
StockManager& sm = StockManager::instance();
SYSPtr sys = SYS_Simple();
sys->setSG(SG_CrossGold(EMA(12), EMA(26)));
sys->setMM(MM_FixedCount(100));
@ -48,10 +39,7 @@ BOOST_AUTO_TEST_CASE( test_PF_for_delay_and_no_adjust) {
AFPtr af = AF_EqualWeight();
PFPtr pf = PF_Simple(tm, se, af);
KQuery query = KQueryByDate(Datetime(201101010000L), Null<Datetime>(),
KQuery::DAY);
KQuery query = KQueryByDate(Datetime(201101010000L), Null<Datetime>(), KQuery::DAY);
/** @arg */
sys->setTM(tm->clone());
@ -65,26 +53,7 @@ BOOST_AUTO_TEST_CASE( test_PF_for_delay_and_no_adjust) {
TradeRecordList tr1 = sys->getTM()->getTradeList();
TradeRecordList tr2 = tm->getTradeList();
BOOST_CHECK(tr1.size() == tr2.size());
/*std::cout << tr1.size() << std::endl;
for (auto iter = tr1.begin(); iter != tr1.end(); ++iter) {
std::cout << *iter << std::endl;
}
std::cout << "==========================" << std::endl;
std::cout << tr2.size() << std::endl;
for (auto iter = tr2.begin(); iter != tr2.end(); ++iter) {
std::cout << *iter << std::endl;
}
std::cout << sys->getTM()->currentCash() << std::endl;
std::cout << tm->currentCash() << std::endl; */
CHECK_EQ(tr1.size(), tr2.size());
}
/** @} */

Some files were not shown because too many files have changed in this diff Show More