Skip to content

Commit

Permalink
cxx actions, more test
Browse files Browse the repository at this point in the history
  • Loading branch information
yssource committed Jun 23, 2021
1 parent 6fbcfd1 commit 2e41f97
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 131 deletions.
44 changes: 35 additions & 9 deletions cxx/test/actions/securitylist/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ using namespace std;

using StockListActionPtr = std::shared_ptr<abq::SecurityListAction<StockList>>;
using IndexListActionPtr = std::shared_ptr<abq::SecurityListAction<IndexList>>;
using MyDataFramePtr = std::shared_ptr<MyDataFrame>;

Q_DECLARE_METATYPE(StockListActionPtr)
Q_DECLARE_METATYPE(IndexListActionPtr)
Q_DECLARE_METATYPE(MyDataFramePtr)

class TestSecurityList : public QObject
{
Expand All @@ -35,6 +38,8 @@ private slots:
void cleanupTestCase();
void get_securities_data();
void get_securities();
void get_dataframe_data();
void get_dataframe();
};

void TestSecurityList::initTestCase() {}
Expand All @@ -48,34 +53,55 @@ void TestSecurityList::initTestCase_data()
auto sa2 = std::make_shared<SecurityListAction<StockList>>(s_codes, end);

QTest::addColumn<StockListActionPtr>("sla");
QTest::addColumn<int>("s_rst");

QStringList i_codes = {"000001", "399001", "399006"};
auto ia = std::make_shared<SecurityListAction<IndexList>>();
auto ia2 = std::make_shared<SecurityListAction<IndexList>>(i_codes, end);

QTest::addColumn<IndexListActionPtr>("ila");
QTest::addColumn<int>("i_rst");

QTest::newRow("0") << sa << 3785 << ia << 1155;
QTest::newRow("1") << sa2 << 3 << ia2 << 3;
QTest::newRow("0") << sa << ia;
QTest::newRow("1") << sa2 << ia2;
}

void TestSecurityList::get_securities_data() {}
void TestSecurityList::get_securities_data()
{
QTest::addColumn<int>("s_rst");
QTest::addColumn<int>("i_rst");
QTest::newRow("0") << 3785 << 1155;
QTest::newRow("1") << 3 << 3;
}

void TestSecurityList::get_securities()
{
QFETCH_GLOBAL(StockListActionPtr, sla);
QFETCH_GLOBAL(int, s_rst);
QFETCH(int, s_rst);
QCOMPARE(sla->get_securities().count(), s_rst);

QFETCH_GLOBAL(IndexListActionPtr, ila);
QFETCH_GLOBAL(int, i_rst);
QFETCH(int, i_rst);
QCOMPARE(ila->get_securities().count(), i_rst);
}

void TestSecurityList::get_dataframe_data()
{
QTest::addColumn<int>("df_rst");
QTest::addColumn<int>("df2_rst");
QTest::newRow("0") << 3785 << 1155;
QTest::newRow("1") << 3 << 3;
}

void TestSecurityList::get_dataframe()
{
QFETCH_GLOBAL(StockListActionPtr, sla);
QFETCH(int, df_rst);
QCOMPARE(sla->get_dataframe()->get_index().size(), df_rst);

QFETCH_GLOBAL(IndexListActionPtr, ila);
QFETCH(int, df2_rst);
QCOMPARE(ila->get_dataframe()->get_index().size(), df2_rst);
}

void TestSecurityList::cleanupTestCase() {}

// ABQ_TEST_SQLLESS_MAIN(TestSecurityList)
ABQ_TEST_MAIN(TestSecurityList)
#include "main.moc"
172 changes: 50 additions & 122 deletions cxx/test/actions/stockday/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,151 +9,79 @@

// #define private public
#include <QtTest/QtTest>
#include <iostream>
#include <utility>

#include "abquant/actions/abquant.hpp"
#include "abquant/actions/security.hpp"
#include "abquant/actions/stockday.hpp"
#include "abquant/actions/stockmin.hpp"
#include "abquant/actions/stockxdxr.hpp"
#include "abquant/actions/utils.hpp"
// #include "gtest/gtest.h"
#include <iostream>
#include <utility>

#include "string"
#include "abquant/models/indexlist.h"
#include "abquant/models/stocklist.h"

using namespace abq;
using namespace std;

// static QList<StockDay> stockdays;
// static MyDataFrame df;
using StockDayActionPtr = std::shared_ptr<abq::StockDayAction>;
using MyDataFramePtr = std::shared_ptr<MyDataFrame>;

Q_DECLARE_METATYPE(StockDayActionPtr)
Q_DECLARE_METATYPE(MyDataFramePtr)

class TestStockDay : public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void initTestCase_data();
void cleanupTestCase();
// void getSize_data();
// void getSize();
// void getFirstObj_data();
// void getFirstObj();
// // void getLastObj_data();
// // void getLastObj();
// void toDataFrame_data();
// void toDataFrame();
// // void parse();
void sma_data();
void sma();
void get_securities_data();
void get_securities();
void get_dataframe_data();
void get_dataframe();
};

void TestStockDay::initTestCase()
void TestStockDay::initTestCase() {}

void TestStockDay::initTestCase_data()
{
QStringList s_codes = {"000001", "300001", "600000"};
const char* start = "2019-12-01";
const char* end = "2019-12-31";

auto sa = std::make_shared<StockDayAction>(s_codes, start, end);

QTest::addColumn<StockDayActionPtr>("sla");

QTest::newRow("0") << sa;
}

void TestStockDay::get_securities_data()
{
QTest::addColumn<int>("s_rst");
QTest::newRow("0") << 66;
}

void TestStockDay::get_securities()
{
// QStringList codes = {"000001", "000002"};
QStringList codes = {"000001"};
const char* start = "2017-01-01";
const char* end = "2019-12-01";

// const char *start = "2019-06-25";
// const char *end = "2019-06-27";

StockDayAction sa(codes, start, end);

// // auto ind = sa.make_indicator<StockDay>();
// auto ind = sa.make_indicator();
// ind.hello<double>(1.1);
// // xt::xarray<double> xs = xt::adapt(sa.to_series<double>("open").toStdVector());
// xt::xarray<double> xs = sa.to_series("open");
// xt::xarray<double> rs = ind.SMA(xs, 12);

// StockMinAction sb(codes, start, end);
// // auto ind2 = sb.make_indicator<StockMin>();
// auto ind2 = sb.make_indicator();
// std::string s{"jimmy"s};
// ind2.hello<std::string>(std::move(s));

// // StockDayAction sa(codes, start, end);
// auto m_codes = sa.get_codes();
// auto df = sa.to_fq_type(FQ_TYPE::PRE);
// // auto df = sa.to_fq_type(FQ_TYPE::POST);
// qDebug() << "m_codes main: " << m_codes << "\n";
// df->write<std::ostream, std::string, double, int>(std::cout);
qDebug() << sa << "\n";

// // sa.set_dataframe();
// auto ddff = sa.get_dataframe();
// auto ooopen = sa.getOpen();
// std::cout << ooopen.size() << "\n";

// StockDayAction sa2(codes, start, end, FQ_TYPE::PRE);
// // sa2.set_dataframe();
// auto xls2 = sa2.to_series("open");
// // auto nn = sa2.getName();

// sa.getName();

// std::cout << xls2.size() << "\n";
// StockMinAction sb(codes, start, end);
// // auto df2 = sb.to_fq_type(FQ_TYPE::PRE);
// auto df2 = sb.to_fq_type(FQ_TYPE::POST);
// qDebug() << sb << "\n";

StockXdxrAction sc(codes);
qDebug() << sc << "\n";

// auto mm0 = sa.to_series<std::string>("code");
// qDebug() << "------- mm0 " << mm0.size() << "\n";
// for (auto o : mm0) {
// for (auto i : o) {
// qDebug() << i;
// }
// }
// qDebug() << "\n code000 \n";

// auto mm = sa.to_series<double>("close");
// for (auto o : mm) {
// for (auto i : o) {
// qDebug() << i;
// }
// }

// auto mm2 = sa.to_series<double>("high");
// for (auto o : mm2) {
// for (auto i : o) {
// qDebug() << i;
// }
// }
// qDebug() << "\n close \n";

// auto mm3 = sa.to_series<QString>("date");
// for (auto o : mm3) {
// for (auto i : o) {
// qDebug() << i;
// }
// }
// qDebug() << "\n date \n";

// auto mm4 = sc.to_series<double>("peigu");
// for (auto o : mm4) {
// for (auto i : o) {
// qDebug() << i;
// }
// }
// qDebug() << "\n xdxr peigu \n";

// qDebug() << sb << "\n";
// stockdays = sa.run(codes, start, end);
// qDebug() << "------ stockdays.size ----: " << stockdays.size() << "\n";
// df = sa.toDataFrame();
// df = sa.to_fq(FQ_TYPE::PRE);
QFETCH_GLOBAL(StockDayActionPtr, sla);
QFETCH(int, s_rst);
QCOMPARE(sla->get_securities().count(), s_rst);
}

void TestStockDay::sma_data() {}
void TestStockDay::get_dataframe_data()
{
QTest::addColumn<int>("df_rst");
QTest::newRow("0") << 66;
}

void TestStockDay::sma() {}
void TestStockDay::get_dataframe()
{
QFETCH_GLOBAL(StockDayActionPtr, sla);
QFETCH(int, df_rst);
QCOMPARE(sla->get_dataframe()->get_index().size(), df_rst);
}

void TestStockDay::cleanupTestCase() {}

// ABQ_TEST_SQLLESS_MAIN(TestStockDay)
ABQ_TEST_MAIN(TestStockDay)
#include "main.moc"

0 comments on commit 2e41f97

Please sign in to comment.