3 #include "stg/user_property.h"
6 #include "testsettings.h"
7 #include "testtariffs.h"
10 #include "testservices.h"
14 struct fee_charge_rules_data {
17 typedef test_group<fee_charge_rules_data> tg;
18 tg fee_charge_rules_test_group("Fee charge rules tests group");
20 typedef tg::object testobject;
22 class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
24 TEST_SETTINGS_LOCAL(unsigned _feeChargeType)
25 : feeChargeType(_feeChargeType)
28 unsigned GetFeeChargeType() const { return feeChargeType; }
31 unsigned feeChargeType;
36 void testobject::test<1>()
38 set_test_name("Check classic rules");
40 TEST_SETTINGS_LOCAL settings(0);
44 TEST_SERVICES services;
45 USER_IMPL user(&settings, &store, &tariffs, &admin, NULL, services);
47 USER_PROPERTY<double> & cash(user.GetProperty().cash);
48 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
50 ensure_equals("user.cash == 0 (initial value)", user.GetProperty().cash, 0);
52 ensure_equals("user.cash == 100 (explicitly set)", user.GetProperty().cash, 100);
56 ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperty().tariffName.ConstData(), "test");
58 ensure_equals("user.cash == 50 (first fee charge)", user.GetProperty().cash, 50);
60 ensure_equals("user.cash == 0 (second fee charge)", user.GetProperty().cash, 0);
62 ensure_equals("user.cash == -50 (third fee charge)", user.GetProperty().cash, -50);
64 ensure_equals("user.cash == -100 (fourth fee charge)", user.GetProperty().cash, -100);
69 void testobject::test<2>()
71 set_test_name("Check second rules (allow fee if cash value is positive)");
73 TEST_SETTINGS_LOCAL settings(1);
77 TEST_SERVICES services;
78 USER_IMPL user(&settings, &store, &tariffs, &admin, NULL, services);
80 USER_PROPERTY<double> & cash(user.GetProperty().cash);
81 USER_PROPERTY<double> & credit(user.GetProperty().credit);
82 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
84 ensure_equals("user.cash == 0 (initial value)", user.GetProperty().cash, 0);
85 ensure_equals("user.credit == 0 (initial value)", user.GetProperty().credit, 0);
87 ensure_equals("user.cash == 100 (explicitly set)", user.GetProperty().cash, 100);
91 ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperty().tariffName.ConstData(), "test");
93 ensure_equals("user.cash == 50 (first fee charge)", user.GetProperty().cash, 50);
95 ensure_equals("user.cash == 0 (second fee charge)", user.GetProperty().cash, 0);
97 ensure_equals("user.cash == -50 (third fee charge)", user.GetProperty().cash, -50);
99 ensure_equals("user.cash == -50 (not charging `cause value is negative)", user.GetProperty().cash, -50);
101 ensure_equals("user.cash == 49 (explicitly set)", user.GetProperty().cash, 49);
102 user.ProcessDayFee();
103 ensure_equals("user.cash == -1 (charge to negative value)", user.GetProperty().cash, -1);
104 user.ProcessDayFee();
105 ensure_equals("user.cash == -1 (not charging `cause value is negative)", user.GetProperty().cash, -1);
107 ensure_equals("user.credit == 50 (explicitly set)", user.GetProperty().credit, 50);
108 user.ProcessDayFee();
109 ensure_equals("user.cash == -51 (charging `cause value + credit gives us a positive value)", user.GetProperty().cash, -51);
110 user.ProcessDayFee();
111 ensure_equals("user.cash == -51 (not charging `cause credit now is not enoght)", user.GetProperty().cash, -51);
116 void testobject::test<3>()
118 set_test_name("Check third rules (allow fee if cash value is greater than fee)");
120 TEST_SETTINGS_LOCAL settings(2);
121 TEST_TARIFFS tariffs;
124 TEST_SERVICES services;
125 USER_IMPL user(&settings, &store, &tariffs, &admin, NULL, services);
127 USER_PROPERTY<double> & cash(user.GetProperty().cash);
128 USER_PROPERTY<double> & credit(user.GetProperty().credit);
129 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
131 ensure_equals("user.cash == 0 (initial value)", user.GetProperty().cash, 0);
133 ensure_equals("user.cash == 100 (explicitly set)", user.GetProperty().cash, 100);
137 ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperty().tariffName.ConstData(), "test");
138 user.ProcessDayFee();
139 ensure_equals("user.cash == 50 (first fee charge)", user.GetProperty().cash, 50);
140 user.ProcessDayFee();
141 ensure_equals("user.cash == 0 (second fee charge)", user.GetProperty().cash, 0);
142 user.ProcessDayFee();
143 ensure_equals("user.cash == 0 (not charging `cause value is lower than fee)", user.GetProperty().cash, 0);
145 ensure_equals("user.cash == 50 (explicitly set)", user.GetProperty().cash, 50);
147 user.ProcessDayFee();
148 ensure_equals("user.cash == 50 (not charging `cause value is lower than fee)", user.GetProperty().cash, 50);
150 ensure_equals("user.cash == 0 (explicitly set)", user.GetProperty().cash, 0);
152 ensure_equals("user.credit == 51 (explicitly set)", user.GetProperty().credit, 51);
153 user.ProcessDayFee();
154 ensure_equals("user.cash == -51 (charging `cause value + credit gives us a value greater than fee)", user.GetProperty().cash, -51);
155 user.ProcessDayFee();
156 ensure_equals("user.cash == -51 (not charging `cause credit now is not enought)", user.GetProperty().cash, -51);