test_doc
test_ProfitGoal.cpp
浏览该文件的文档.
1 /*
2  * test_ProfitGoal.cpp
3  *
4  * Created on: 2013-3-21
5  * Author: fasiondog
6  */
7 
8 #ifdef TEST_ALL_IN_ONE
9  #include <boost/test/unit_test.hpp>
10 #else
11  #define BOOST_TEST_MODULE test_hikyuu_trade_sys_suite
12  #include <boost/test/unit_test.hpp>
13 #endif
14 
15 #include <hikyuu/StockManager.h>
16 #include <hikyuu/trade_sys/profitgoal/ProfitGoalBase.h>
17 
18 using namespace hku;
19 
20 class ProfitGoalTest: public ProfitGoalBase {
21 public:
22  ProfitGoalTest(): ProfitGoalBase("ProfitGoalTest"), m_x(0) {}
23  virtual ~ProfitGoalTest() {}
24 
25  virtual price_t getGoal(const Datetime& datetime, price_t price) {
26  return m_x < 10 ? 0.0 : 1.0;
27  }
28 
29  virtual void _reset() {
30  m_x = 0;
31  }
32 
33  virtual ProfitGoalPtr _clone() {
35  p->m_x = m_x;
36  return ProfitGoalPtr(p);
37  }
38 
39  virtual void _calculate() {}
40 
41  int getX() const { return m_x;}
42  void setX(int x) { m_x = x; }
43 
44 private:
45  int m_x;
46 };
47 
55 BOOST_AUTO_TEST_CASE( test_ProfitGoal) {
57  ProfitGoalPtr p(new ProfitGoalTest);
58  BOOST_CHECK(p->name() == "ProfitGoalTest");
59  BOOST_CHECK(p->getGoal(Datetime(200101010000), 1.0) == 0.0);
60  ProfitGoalTest *p_src = (ProfitGoalTest *)p.get();
61  BOOST_CHECK(p_src->getX() == 0);
62 
63  p_src->setX(10);
64  BOOST_CHECK(p->getGoal(Datetime(200101010000), 1.0) == 1.0);
65  BOOST_CHECK(p_src->getX() == 10);
66  p->reset();
67  BOOST_CHECK(p_src->getX() == 0);
68 
70  p_src->setX(10);
71  ProfitGoalPtr p_clone = p->clone();
72  BOOST_CHECK(p_clone->name() == "ProfitGoalTest");
73  p_src = (ProfitGoalTest *)p_clone.get();
74  BOOST_CHECK(p_src->getX() == 10);
75  BOOST_CHECK(p != p_clone);
76 }
77 
virtual void _calculate()
void setX(int x)
int getX() const
virtual price_t getGoal(const Datetime &datetime, price_t price)
virtual ProfitGoalPtr _clone()
BOOST_AUTO_TEST_CASE(test_ProfitGoal)
virtual void _reset()
virtual ~ProfitGoalTest()