-
Notifications
You must be signed in to change notification settings - Fork 1
/
account_test.cpp
78 lines (62 loc) · 2.1 KB
/
account_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <gtest/gtest.h>
#include "account.hpp"
TEST(TestAccount, order_lots)
{
account acc("Test_order_lots",spdlog::stdout_color_mt("Test_order_lots"));
acc.addMoney(10000);
acc.order_lots(1,1000);
ASSERT_FLOAT_EQ(acc.getMoney(),10000);
acc.order_lots(1, 1);
ASSERT_FLOAT_EQ(acc.getMoney(),9900);
ASSERT_EQ(acc.getStockAmount(),1);
acc.order_lots(10,1);
ASSERT_FLOAT_EQ(acc.getMoney(),8900);
ASSERT_EQ(acc.getStockAmount(), 2);
}
TEST(TestAccount, order_percnet)
{
account acc("Test_order_percent",spdlog::stdout_color_mt("Test_order_percent"));
acc.addMoney(10000);
acc.order_percent(1,1);
ASSERT_EQ(acc.getStockAmount(),100);
ASSERT_FLOAT_EQ(acc.getMoney(),0);
acc.order_percent(1,-0.5);
EXPECT_EQ(acc.getStockAmount(),50);
acc.order_percent(1,0.5);
EXPECT_EQ(acc.getStockAmount(),75);
}
TEST(TestAccount, order_target_percent)
{
account acc("Test_order_target_percent",spdlog::stdout_color_mt("Test_order_target_percent"));
acc.addMoney(10000);
acc.order_target_percent(1,0.1);
ASSERT_EQ(acc.getStockAmount(),10);
ASSERT_FLOAT_EQ(acc.getMoney(),9000);
acc.order_target_percent(1,1.2);
ASSERT_EQ(acc.getStockAmount(),10);
ASSERT_FLOAT_EQ(acc.getMoney(),9000);
acc.order_target_percent(1,-0.3);
ASSERT_EQ(acc.getStockAmount(),10);
ASSERT_FLOAT_EQ(acc.getMoney(),9000);
acc.order_target_percent(10,0.5);
ASSERT_EQ(acc.getStockAmount(),10);
ASSERT_FLOAT_EQ(acc.getMoney(),9000);
acc.order_target_percent(10,1);
ASSERT_EQ(acc.getStockAmount(),19);
ASSERT_FLOAT_EQ(acc.getMoney(),0);
acc.order_target_percent(9,0);
ASSERT_EQ(acc.getStockAmount(),0);
ASSERT_FLOAT_EQ(acc.getMoney(),17100);
acc.order_target_percent(1,0.01);
ASSERT_EQ(acc.getStockAmount(),1);
ASSERT_FLOAT_EQ(acc.getMoney(),17000);
acc.order_target_percent(1,0);
acc.order_target_percent(1,0.02);
ASSERT_EQ(acc.getStockAmount(),3);
ASSERT_FLOAT_EQ(acc.getMoney(),16800);
}
int main(int argc, char* argv[])
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}