3 #include "stg/user_property.h"
6 #include "testsettings.h"
7 #include "testtariffs.h"
13 struct fee_charge_rules_data {
16 typedef test_group<fee_charge_rules_data> tg;
17 tg fee_charge_rules_test_group("Fee charge rules tests group");
19 typedef tg::object testobject;
21 class TEST_SETTINGS_LOCAL : public TEST_SETTINGS {
23 TEST_SETTINGS_LOCAL(unsigned _feeChargeType)
24 : feeChargeType(_feeChargeType)
27 unsigned GetFeeChargeType() const { return feeChargeType; }
30 unsigned feeChargeType;
35 void testobject::test<1>()
37 set_test_name("Check classic rules");
39 TEST_SETTINGS_LOCAL settings(0);
43 USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
45 USER_PROPERTY<double> & cash(user.GetProperty().cash);
46 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
48 ensure_equals("user.cash == 0 (initial value)", user.GetProperty().cash, 0);
50 ensure_equals("user.cash == 100 (explicitly set)", user.GetProperty().cash, 100);
54 ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperty().tariffName.ConstData(), "test");
56 ensure_equals("user.cash == 50 (first fee charge)", user.GetProperty().cash, 50);
58 ensure_equals("user.cash == 0 (second fee charge)", user.GetProperty().cash, 0);
60 ensure_equals("user.cash == -50 (third fee charge)", user.GetProperty().cash, -50);
62 ensure_equals("user.cash == -100 (fourth fee charge)", user.GetProperty().cash, -100);
67 void testobject::test<2>()
69 set_test_name("Check second rules (allow fee if cash value is positive)");
71 TEST_SETTINGS_LOCAL settings(1);
75 USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
77 USER_PROPERTY<double> & cash(user.GetProperty().cash);
78 USER_PROPERTY<double> & credit(user.GetProperty().credit);
79 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
81 ensure_equals("user.cash == 0 (initial value)", user.GetProperty().cash, 0);
82 ensure_equals("user.credit == 0 (initial value)", user.GetProperty().credit, 0);
84 ensure_equals("user.cash == 100 (explicitly set)", user.GetProperty().cash, 100);
88 ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperty().tariffName.ConstData(), "test");
90 ensure_equals("user.cash == 50 (first fee charge)", user.GetProperty().cash, 50);
92 ensure_equals("user.cash == 0 (second fee charge)", user.GetProperty().cash, 0);
94 ensure_equals("user.cash == -50 (third fee charge)", user.GetProperty().cash, -50);
96 ensure_equals("user.cash == -50 (not charging `cause value is negative)", user.GetProperty().cash, -50);
98 ensure_equals("user.cash == 49 (explicitly set)", user.GetProperty().cash, 49);
100 ensure_equals("user.cash == -1 (charge to negative value)", user.GetProperty().cash, -1);
101 user.ProcessDayFee();
102 ensure_equals("user.cash == -1 (not charging `cause value is negative)", user.GetProperty().cash, -1);
104 ensure_equals("user.credit == 50 (explicitly set)", user.GetProperty().credit, 50);
105 user.ProcessDayFee();
106 ensure_equals("user.cash == -51 (charging `cause value + credit gives us a positive value)", user.GetProperty().cash, -51);
107 user.ProcessDayFee();
108 ensure_equals("user.cash == -51 (not charging `cause credit now is not enoght)", user.GetProperty().cash, -51);
113 void testobject::test<3>()
115 set_test_name("Check third rules (allow fee if cash value is greater than fee)");
117 TEST_SETTINGS_LOCAL settings(2);
118 TEST_TARIFFS tariffs;
121 USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
123 USER_PROPERTY<double> & cash(user.GetProperty().cash);
124 USER_PROPERTY<double> & credit(user.GetProperty().credit);
125 USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
127 ensure_equals("user.cash == 0 (initial value)", user.GetProperty().cash, 0);
129 ensure_equals("user.cash == 100 (explicitly set)", user.GetProperty().cash, 100);
133 ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperty().tariffName.ConstData(), "test");
134 user.ProcessDayFee();
135 ensure_equals("user.cash == 50 (first fee charge)", user.GetProperty().cash, 50);
136 user.ProcessDayFee();
137 ensure_equals("user.cash == 0 (second fee charge)", user.GetProperty().cash, 0);
138 user.ProcessDayFee();
139 ensure_equals("user.cash == 0 (not charging `cause value is lower than fee)", user.GetProperty().cash, 0);
141 ensure_equals("user.cash == 50 (explicitly set)", user.GetProperty().cash, 50);
143 user.ProcessDayFee();
144 ensure_equals("user.cash == 50 (not charging `cause value is lower than fee)", user.GetProperty().cash, 50);
146 ensure_equals("user.cash == 0 (explicitly set)", user.GetProperty().cash, 0);
148 ensure_equals("user.credit == 51 (explicitly set)", user.GetProperty().credit, 51);
149 user.ProcessDayFee();
150 ensure_equals("user.cash == -51 (charging `cause value + credit gives us a value greater than fee)", user.GetProperty().cash, -51);
151 user.ProcessDayFee();
152 ensure_equals("user.cash == -51 (not charging `cause credit now is not enought)", user.GetProperty().cash, -51);