/*
* test_Stock.cpp
*
* Created on: 2011-12-10
* Author: fasiondog
*/
#include "doctest/doctest.h"
#include <cmath>
#include <hikyuu/StockManager.h>
#include <hikyuu/KQuery.h>
#include <hikyuu/KData.h>
#include <hikyuu/Stock.h>
using namespace hku;
#define MEMORY_CHECK \
{ \
Stock mem_stock = sm["sh000001"]; \
CHECK_EQ(mem_stock.isBuffer(KQuery::DAY), true); \
CHECK_EQ(mem_stock.isBuffer(KQuery::WEEK), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::MONTH), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::QUARTER), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::HALFYEAR), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::YEAR), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::MIN), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::MIN5), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::MIN15), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::MIN30), false); \
CHECK_EQ(mem_stock.isBuffer(KQuery::MIN60), false); \
}
/**
* @defgroup test_hikyuu_Stock test_hikyuu_Stock
* @ingroup test_hikyuu_base_suite
* @{
*/
/** @par 检测点 */
TEST_CASE("test_Stock_Relational_comparison") {
StockManager& sm = StockManager::instance();
Stock s1;
/** @arg 和Null<Stock>()进行相等比较 */
CHECK_EQ(s1, Null<Stock>());
/** @arg 和Null<Stock>()进行不等比较 */
s1 = sm.getStock("sh000001");
CHECK_NE(s1, Null<Stock>());
/** @arg 相等比较 */
Stock s2 = sm.getStock("sh000001");
CHECK_EQ(s1, s2);
/** @arg 不等比较 */
s2 = sm.getStock("sz000001");
CHECK_NE(s1, s2);
MEMORY_CHECK;
}
/** @par 检测点 */
TEST_CASE("test_Stock_getWeight") {
StockManager& sm = StockManager::instance();
Stock stock = sm.getStock("sz000001");
StockWeight weight;
/** @arg 查询全部权息信息 */
StockWeightList weightList = stock.getWeight();
CHECK_EQ(weightList.size(), 23);
weight = weightList.front();
CHECK_EQ(weight.datetime(), Datetime(199104030000L));
CHECK_EQ(weight.countAsGift(), 0.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 0.0);
CHECK_EQ(weight.increasement(), 0.0);
CHECK_EQ(weight.totalCount(), 150);
CHECK_EQ(weight.freeCount(), 68);
weight = weightList.back();
CHECK_EQ(weight.datetime(), Datetime(201108050000L));
CHECK_EQ(weight.countAsGift(), 0.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 0.0);
CHECK_EQ(weight.increasement(), 0.0);
CHECK_EQ(weight.totalCount(), 512335);
CHECK_EQ(weight.freeCount(), 310536);
/** @arg 查询指定日期范围内的权息信息,指定的起始日期和结束日期没有刚好对应的权息记录 */
weightList = stock.getWeight(Datetime(199501010000), Datetime(199701010000));
CHECK_EQ(weightList.size(), 2);
weight = weightList.front();
CHECK_EQ(weight.datetime(), Datetime(199509250000));
CHECK_EQ(weight.countAsGift(), 2.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 3.0);
CHECK_EQ(weight.increasement(), 0.0);
CHECK_EQ(weight.totalCount(), 51728);
CHECK_EQ(weight.freeCount(), 35721);
weight = weightList.back();
CHECK_EQ(weight.datetime(), Datetime(199605270000));
CHECK_EQ(weight.countAsGift(), 5.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 0.0);
CHECK_EQ(weight.increasement(), 5.0);
CHECK_EQ(weight.totalCount(), 103456);
CHECK_EQ(weight.freeCount(), 71393);
/** @arg 查询指定日期范围内的权息信息,指定的起始日期刚好存在对应权息记录,而结束日期没有 */
weightList = stock.getWeight(Datetime(199509250000), Datetime(199701010000));
CHECK_EQ(weightList.size(), 2);
weight = weightList.front();
CHECK_EQ(weight.datetime(), Datetime(199509250000));
CHECK_EQ(weight.countAsGift(), 2.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 3.0);
CHECK_EQ(weight.increasement(), 0.0);
CHECK_EQ(weight.totalCount(), 51728);
CHECK_EQ(weight.freeCount(), 35721);
weight = weightList.back();
CHECK_EQ(weight.datetime(), Datetime(199605270000));
CHECK_EQ(weight.countAsGift(), 5.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 0.0);
CHECK_EQ(weight.increasement(), 5.0);
CHECK_EQ(weight.totalCount(), 103456);
CHECK_EQ(weight.freeCount(), 71393);
/** @arg 查询指定日期范围内的权息信息,指定的结束日期刚好存在对应权息记录,而起始日期没有 */
weightList = stock.getWeight(Datetime(199501010000), Datetime(199605270000));
CHECK_EQ(weightList.size(), 1);
weight = weightList.front();
CHECK_EQ(weight.datetime(), Datetime(199509250000));
CHECK_EQ(weight.countAsGift(), 2.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 3.0);
CHECK_EQ(weight.increasement(), 0.0);
CHECK_EQ(weight.totalCount(), 51728);
CHECK_EQ(weight.freeCount(), 35721);
/** @arg 查询指定日期范围内的权息信息,结束日期为Null<Datetime>() */
weightList = stock.getWeight(Datetime(201101010000), Null<Datetime>());
CHECK_EQ(weightList.size(), 1);
weight = weightList.front();
CHECK_EQ(weight.datetime(), Datetime(201108050000));
CHECK_EQ(weight.countAsGift(), 0.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 0.0);
CHECK_EQ(weight.increasement(), 0.0);
CHECK_EQ(weight.totalCount(), 512335);
CHECK_EQ(weight.freeCount(), 310536);
/** @arg 查询指定日期范围内的权息信息,只指定起始日期,结束日期为默认值 */
weightList = stock.getWeight(Datetime(201101010000));
CHECK_EQ(weightList.size(), 1);
weight = weightList.front();
CHECK_EQ(weight.datetime(), Datetime(201108050000));
CHECK_EQ(weight.countAsGift(), 0.0);
CHECK_EQ(weight.countForSell(), 0.0);
CHECK_EQ(weight.priceForSell(), 0.0);
CHECK_EQ(weight.bonus(), 0.0);
CHECK_EQ(weight.increasement(), 0.0);
CHECK_EQ(weight.totalCount(), 512335);
CHECK_EQ(weight.freeCount(), 310536);
MEMORY_CHECK;
}
/** @par 检测点 */
TEST_CASE("test_Stock_getCount") {
StockManager& sm = StockManager::instance();
/** @arg 查询sh000001的日线数量*/
Stock stock = sm.getStock("sh000001");
CHECK_EQ(stock.getCount(KQuery::DAY), 5121);
/** @arg 查询sz000001的日线数量 */
stock = sm.getStock("Sz000001");
CHECK_EQ(stock.getCount(KQuery::DAY), 4937);
/** @arg 查询sh000001的周线数量*/
stock = sm.getStock("sh000001");
CHECK_EQ(stock.getCount(KQuery::WEEK), 1059);
/** @arg 查询sz000001的周线数量 */
stock = sm.getStock("Sz000001");
CHECK_EQ(stock.getCount(KQuery::WEEK), 1037);
/** @arg 查询sh000001的月线数量*/
stock = sm.getStock("sh000001");
CHECK_EQ(stock.getCount(KQuery::MONTH), 253);
/** @arg 查询sz000001的月线数量 */
stock = sm.getStock("Sz000001");
CHECK_EQ(stock.getCount(KQuery::MONTH), 250);
/** @arg 查询sh000001的季线数量*/
stock = sm.getStock("sh000001");
CHECK_EQ(stock.getCount(KQuery::QUARTER), 85);
/** @arg 查询sz000001的季线数量 */
stock = sm.getStock("Sz000001");
CHECK_EQ(stock.getCount(KQuery::QUARTER), 84);
/** @arg 查询sh000001的半年线数量*/
stock = sm.getStock("sh000001");
CHECK_EQ(stock.getCount(KQuery: