1 #define BOOST_TEST_MODULE STGTariff
3 #include "stg/tariff_conf.h"
4 #include "tariff_impl.h"
6 #pragma GCC diagnostic push
7 #pragma GCC diagnostic ignored "-Wold-style-cast"
8 #pragma GCC diagnostic ignored "-Wunused-parameter"
9 #pragma GCC diagnostic ignored "-Wsign-compare"
10 #pragma GCC diagnostic ignored "-Wparentheses"
11 #include <boost/test/unit_test.hpp>
12 #pragma GCC diagnostic pop
19 constexpr double TOLERANCE = 0.01;
21 time_t makeTime(unsigned hour, unsigned minute)
24 time_t now = time(nullptr);
25 localtime_r(&now, &brokenTime);
26 brokenTime.tm_hour = hour;
27 brokenTime.tm_min = minute;
28 brokenTime.tm_sec = 0;
29 return mktime(&brokenTime);
34 BOOST_AUTO_TEST_SUITE(Tariffs)
36 BOOST_AUTO_TEST_CASE(Construction)
38 STG::TariffData td("test");
39 td.tariffConf.fee = 1;
40 td.tariffConf.free = 2;
41 td.tariffConf.traffType = STG::Tariff::TRAFF_UP_DOWN;
42 td.tariffConf.passiveCost = 4;
43 td.dirPrice[0].mDay = 30;
44 td.dirPrice[0].hDay = 9;
45 td.dirPrice[0].mNight = 30;
46 td.dirPrice[0].hNight = 21;
47 td.dirPrice[0].priceDayA = 0;
48 td.dirPrice[0].priceDayB = 1;
49 td.dirPrice[0].priceNightA = 2;
50 td.dirPrice[0].priceNightB = 3;
51 td.dirPrice[0].threshold = 4;
52 td.dirPrice[0].singlePrice = 0;
53 td.dirPrice[0].noDiscount = 0;
54 const STG::TariffImpl tariff(td);
56 BOOST_CHECK(tariff.GetFreeMb() == td.tariffConf.free);
57 BOOST_CHECK(tariff.GetPassiveCost() == td.tariffConf.passiveCost);
58 BOOST_CHECK(tariff.GetFee() == td.tariffConf.fee);
59 BOOST_CHECK(tariff.GetFree() == td.tariffConf.free);
60 BOOST_CHECK(tariff.GetName() == td.tariffConf.name);
61 BOOST_CHECK(tariff.GetTraffType() == td.tariffConf.traffType);
62 BOOST_CHECK(tariff.GetThreshold(0) == td.dirPrice[0].threshold);
63 BOOST_CHECK_EQUAL(tariff.GetTraffByType(6, 0), 6);
64 BOOST_CHECK_EQUAL(tariff.GetTraffByType(5, 1), 6);
65 BOOST_CHECK_EQUAL(tariff.GetTraffByType(4, 2), 6);
66 BOOST_CHECK_EQUAL(tariff.GetTraffByType(3, 3), 6);
67 BOOST_CHECK_EQUAL(tariff.GetTraffByType(2, 4), 6);
68 BOOST_CHECK_EQUAL(tariff.GetTraffByType(1, 5), 6);
69 BOOST_CHECK_EQUAL(tariff.GetTraffByType(0, 6), 6);
72 BOOST_AUTO_TEST_CASE(TraffTypes)
74 STG::TariffData td("test");
75 td.tariffConf.fee = 1;
76 td.tariffConf.free = 2;
77 td.tariffConf.traffType = STG::Tariff::TRAFF_UP;
78 td.tariffConf.passiveCost = 4;
79 td.dirPrice[0].mDay = 30;
80 td.dirPrice[0].hDay = 9;
81 td.dirPrice[0].mNight = 30;
82 td.dirPrice[0].hNight = 21;
83 td.dirPrice[0].priceDayA = 0;
84 td.dirPrice[0].priceDayB = 1;
85 td.dirPrice[0].priceNightA = 2;
86 td.dirPrice[0].priceNightB = 3;
87 td.dirPrice[0].threshold = 4;
88 td.dirPrice[0].singlePrice = 0;
89 td.dirPrice[0].noDiscount = 0;
90 STG::TariffImpl tariff(td);
92 BOOST_CHECK(tariff.GetTraffType() == STG::Tariff::TRAFF_UP);
93 BOOST_CHECK_EQUAL(tariff.GetTraffByType(6, 0), 6);
94 BOOST_CHECK_EQUAL(tariff.GetTraffByType(5, 1), 5);
95 BOOST_CHECK_EQUAL(tariff.GetTraffByType(4, 2), 4);
96 BOOST_CHECK_EQUAL(tariff.GetTraffByType(3, 3), 3);
97 BOOST_CHECK_EQUAL(tariff.GetTraffByType(2, 4), 2);
98 BOOST_CHECK_EQUAL(tariff.GetTraffByType(1, 5), 1);
99 BOOST_CHECK_EQUAL(tariff.GetTraffByType(0, 6), 0);
101 td.tariffConf.traffType = STG::Tariff::TRAFF_DOWN;
104 BOOST_CHECK(tariff.GetTraffType() == STG::Tariff::TRAFF_DOWN);
105 BOOST_CHECK_EQUAL(tariff.GetTraffByType(6, 0), 0);
106 BOOST_CHECK_EQUAL(tariff.GetTraffByType(5, 1), 1);
107 BOOST_CHECK_EQUAL(tariff.GetTraffByType(4, 2), 2);
108 BOOST_CHECK_EQUAL(tariff.GetTraffByType(3, 3), 3);
109 BOOST_CHECK_EQUAL(tariff.GetTraffByType(2, 4), 4);
110 BOOST_CHECK_EQUAL(tariff.GetTraffByType(1, 5), 5);
111 BOOST_CHECK_EQUAL(tariff.GetTraffByType(0, 6), 6);
113 td.tariffConf.traffType = STG::Tariff::TRAFF_MAX;
116 BOOST_CHECK(tariff.GetTraffType() == STG::Tariff::TRAFF_MAX);
117 BOOST_CHECK_EQUAL(tariff.GetTraffByType(6, 0), 6);
118 BOOST_CHECK_EQUAL(tariff.GetTraffByType(5, 1), 5);
119 BOOST_CHECK_EQUAL(tariff.GetTraffByType(4, 2), 4);
120 BOOST_CHECK_EQUAL(tariff.GetTraffByType(3, 3), 3);
121 BOOST_CHECK_EQUAL(tariff.GetTraffByType(2, 4), 4);
122 BOOST_CHECK_EQUAL(tariff.GetTraffByType(1, 5), 5);
123 BOOST_CHECK_EQUAL(tariff.GetTraffByType(0, 6), 6);
125 td.tariffConf.traffType = STG::Tariff::TRAFF_UP_DOWN;
128 BOOST_CHECK(tariff.GetTraffType() == STG::Tariff::TRAFF_UP_DOWN);
129 BOOST_CHECK_EQUAL(tariff.GetTraffByType(6, 0), 6);
130 BOOST_CHECK_EQUAL(tariff.GetTraffByType(5, 1), 6);
131 BOOST_CHECK_EQUAL(tariff.GetTraffByType(4, 2), 6);
132 BOOST_CHECK_EQUAL(tariff.GetTraffByType(3, 3), 6);
133 BOOST_CHECK_EQUAL(tariff.GetTraffByType(2, 4), 6);
134 BOOST_CHECK_EQUAL(tariff.GetTraffByType(1, 5), 6);
135 BOOST_CHECK_EQUAL(tariff.GetTraffByType(0, 6), 6);
138 BOOST_AUTO_TEST_CASE(NormalIntervalPrices)
140 STG::TariffData td("test");
141 td.tariffConf.fee = 1;
142 td.tariffConf.free = 2;
143 td.tariffConf.traffType = STG::Tariff::TRAFF_UP_DOWN;
144 td.tariffConf.passiveCost = 4;
145 td.dirPrice[0].mDay = 30;
146 td.dirPrice[0].hDay = 9;
147 td.dirPrice[0].mNight = 30;
148 td.dirPrice[0].hNight = 21;
149 td.dirPrice[0].priceDayA = 0;
150 td.dirPrice[0].priceDayB = 1;
151 td.dirPrice[0].priceNightA = 2;
152 td.dirPrice[0].priceNightB = 3;
153 td.dirPrice[0].threshold = 4;
154 td.dirPrice[0].singlePrice = 0;
155 td.dirPrice[0].noDiscount = 0;
156 STG::TariffImpl tariff(td);
158 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(17, 20)), 0, TOLERANCE); // Near 17:30, 0 < 4 DA
159 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(17, 20)), 1, TOLERANCE); // Near 17:30, 6 > 4 DB
160 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(22, 20)), 2, TOLERANCE); // Near 22:30, 0 < 4 NA
161 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(22, 20)), 3, TOLERANCE); // Near 22:30, 6 > 4 NB
163 td.dirPrice[0].singlePrice = 1;
166 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(17, 20)), 0, TOLERANCE); // Near 17:30, 0 < 4 DA
167 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(17, 20)), 1, TOLERANCE); // Near 17:30, 6 > 4 DB
168 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(22, 20)), 0, TOLERANCE); // Near 22:30, 0 < 4 DA
169 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(22, 20)), 1, TOLERANCE); // Near 22:30, 6 > 4 DB
171 td.dirPrice[0].singlePrice = 0;
172 td.dirPrice[0].noDiscount = 1;
175 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(17, 20)), 0, TOLERANCE); // Near 17:30, 0 < 4 DA
176 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(17, 20)), 0, TOLERANCE); // Near 17:30, 6 > 4 DA
177 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(22, 20)), 2, TOLERANCE); // Near 22:30, 0 < 4 NA
178 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(22, 20)), 2, TOLERANCE); // Near 22:30, 6 > 4 NA
180 td.dirPrice[0].singlePrice = 1;
181 td.dirPrice[0].noDiscount = 1;
184 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(17, 20)), 0, TOLERANCE); // Near 17:30, 0 < 4 DA
185 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(17, 20)), 0, TOLERANCE); // Near 17:30, 6 > 4 DA
186 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(22, 20)), 0, TOLERANCE); // Near 22:30, 0 < 4 DA
187 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(22, 20)), 0, TOLERANCE); // Near 22:30, 6 > 4 DA
190 BOOST_AUTO_TEST_CASE(ConstructionForDayNightInversion)
192 STG::TariffData td("test");
193 td.tariffConf.fee = 1;
194 td.tariffConf.free = 2;
195 td.tariffConf.traffType = STG::Tariff::TRAFF_UP_DOWN;
196 td.tariffConf.passiveCost = 4;
197 td.dirPrice[0].mDay = 30;
198 td.dirPrice[0].hDay = 21;
199 td.dirPrice[0].mNight = 30;
200 td.dirPrice[0].hNight = 9;
201 td.dirPrice[0].priceDayA = 0;
202 td.dirPrice[0].priceDayB = 1;
203 td.dirPrice[0].priceNightA = 2;
204 td.dirPrice[0].priceNightB = 3;
205 td.dirPrice[0].threshold = 4;
206 td.dirPrice[0].singlePrice = 0;
207 td.dirPrice[0].noDiscount = 0;
208 const STG::TariffImpl tariff(td);
210 BOOST_CHECK(tariff.GetFreeMb() == td.tariffConf.free);
211 BOOST_CHECK(tariff.GetPassiveCost() == td.tariffConf.passiveCost);
212 BOOST_CHECK(tariff.GetFee() == td.tariffConf.fee);
213 BOOST_CHECK(tariff.GetFree() == td.tariffConf.free);
214 BOOST_CHECK(tariff.GetName() == td.tariffConf.name);
215 BOOST_CHECK(tariff.GetTraffType() == td.tariffConf.traffType);
216 BOOST_CHECK(tariff.GetThreshold(0) == td.dirPrice[0].threshold);
217 BOOST_CHECK_EQUAL(tariff.GetTraffByType(6, 0), 6);
218 BOOST_CHECK_EQUAL(tariff.GetTraffByType(5, 1), 6);
219 BOOST_CHECK_EQUAL(tariff.GetTraffByType(4, 2), 6);
220 BOOST_CHECK_EQUAL(tariff.GetTraffByType(3, 3), 6);
221 BOOST_CHECK_EQUAL(tariff.GetTraffByType(2, 4), 6);
222 BOOST_CHECK_EQUAL(tariff.GetTraffByType(1, 5), 6);
223 BOOST_CHECK_EQUAL(tariff.GetTraffByType(0, 6), 6);
226 BOOST_AUTO_TEST_CASE(TraffTypeForDayNightInversion)
228 STG::TariffData td("test");
229 td.tariffConf.fee = 1;
230 td.tariffConf.free = 2;
231 td.tariffConf.traffType = STG::Tariff::TRAFF_UP;
232 td.tariffConf.passiveCost = 4;
233 td.dirPrice[0].mDay = 30;
234 td.dirPrice[0].hDay = 21;
235 td.dirPrice[0].mNight = 30;
236 td.dirPrice[0].hNight = 9;
237 td.dirPrice[0].priceDayA = 0;
238 td.dirPrice[0].priceDayB = 1;
239 td.dirPrice[0].priceNightA = 2;
240 td.dirPrice[0].priceNightB = 3;
241 td.dirPrice[0].threshold = 4;
242 td.dirPrice[0].singlePrice = 0;
243 td.dirPrice[0].noDiscount = 0;
244 STG::TariffImpl tariff(td);
246 BOOST_CHECK(tariff.GetTraffType() == STG::Tariff::TRAFF_UP);
247 BOOST_CHECK_EQUAL(tariff.GetTraffByType(6, 0), 6);
248 BOOST_CHECK_EQUAL(tariff.GetTraffByType(5, 1), 5);
249 BOOST_CHECK_EQUAL(tariff.GetTraffByType(4, 2), 4);
250 BOOST_CHECK_EQUAL(tariff.GetTraffByType(3, 3), 3);
251 BOOST_CHECK_EQUAL(tariff.GetTraffByType(2, 4), 2);
252 BOOST_CHECK_EQUAL(tariff.GetTraffByType(1, 5), 1);
253 BOOST_CHECK_EQUAL(tariff.GetTraffByType(0, 6), 0);
255 td.tariffConf.traffType = STG::Tariff::TRAFF_DOWN;
258 BOOST_CHECK(tariff.GetTraffType() == STG::Tariff::TRAFF_DOWN);
259 BOOST_CHECK_EQUAL(tariff.GetTraffByType(6, 0), 0);
260 BOOST_CHECK_EQUAL(tariff.GetTraffByType(5, 1), 1);
261 BOOST_CHECK_EQUAL(tariff.GetTraffByType(4, 2), 2);
262 BOOST_CHECK_EQUAL(tariff.GetTraffByType(3, 3), 3);
263 BOOST_CHECK_EQUAL(tariff.GetTraffByType(2, 4), 4);
264 BOOST_CHECK_EQUAL(tariff.GetTraffByType(1, 5), 5);
265 BOOST_CHECK_EQUAL(tariff.GetTraffByType(0, 6), 6);
267 td.tariffConf.traffType = STG::Tariff::TRAFF_MAX;
270 BOOST_CHECK(tariff.GetTraffType() == STG::Tariff::TRAFF_MAX);
271 BOOST_CHECK_EQUAL(tariff.GetTraffByType(6, 0), 6);
272 BOOST_CHECK_EQUAL(tariff.GetTraffByType(5, 1), 5);
273 BOOST_CHECK_EQUAL(tariff.GetTraffByType(4, 2), 4);
274 BOOST_CHECK_EQUAL(tariff.GetTraffByType(3, 3), 3);
275 BOOST_CHECK_EQUAL(tariff.GetTraffByType(2, 4), 4);
276 BOOST_CHECK_EQUAL(tariff.GetTraffByType(1, 5), 5);
277 BOOST_CHECK_EQUAL(tariff.GetTraffByType(0, 6), 6);
279 td.tariffConf.traffType = STG::Tariff::TRAFF_UP_DOWN;
282 BOOST_CHECK(tariff.GetTraffType() == STG::Tariff::TRAFF_UP_DOWN);
283 BOOST_CHECK_EQUAL(tariff.GetTraffByType(6, 0), 6);
284 BOOST_CHECK_EQUAL(tariff.GetTraffByType(5, 1), 6);
285 BOOST_CHECK_EQUAL(tariff.GetTraffByType(4, 2), 6);
286 BOOST_CHECK_EQUAL(tariff.GetTraffByType(3, 3), 6);
287 BOOST_CHECK_EQUAL(tariff.GetTraffByType(2, 4), 6);
288 BOOST_CHECK_EQUAL(tariff.GetTraffByType(1, 5), 6);
289 BOOST_CHECK_EQUAL(tariff.GetTraffByType(0, 6), 6);
292 BOOST_AUTO_TEST_CASE(NormalIntervalPricesForDayNightInversion)
294 STG::TariffData td("test");
295 td.tariffConf.fee = 1;
296 td.tariffConf.free = 2;
297 td.tariffConf.traffType = STG::Tariff::TRAFF_UP_DOWN;
298 td.tariffConf.passiveCost = 4;
299 td.dirPrice[0].mDay = 30;
300 td.dirPrice[0].hDay = 21;
301 td.dirPrice[0].mNight = 30;
302 td.dirPrice[0].hNight = 9;
303 td.dirPrice[0].priceDayA = 0;
304 td.dirPrice[0].priceDayB = 1;
305 td.dirPrice[0].priceNightA = 2;
306 td.dirPrice[0].priceNightB = 3;
307 td.dirPrice[0].threshold = 4;
308 td.dirPrice[0].singlePrice = 0;
309 td.dirPrice[0].noDiscount = 0;
310 STG::TariffImpl tariff(td);
312 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(17, 20)), 2, TOLERANCE); // Near 17:30, 0 < 4 NA
313 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(17, 20)), 3, TOLERANCE); // Near 17:30, 6 > 4 NB
314 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(22, 20)), 0, TOLERANCE); // Near 22:30, 0 < 4 DA
315 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(22, 20)), 1, TOLERANCE); // Near 22:30, 6 > 4 DB
317 td.dirPrice[0].singlePrice = 1;
320 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(17, 20)), 0, TOLERANCE); // Near 17:30, 0 < 4 DA (ignore night)
321 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(17, 20)), 1, TOLERANCE); // Near 17:30, 6 > 4 DB (ignore night)
322 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(22, 20)), 0, TOLERANCE); // Near 22:30, 0 < 4 DA (ignore night)
323 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(22, 20)), 1, TOLERANCE); // Near 22:30, 6 > 4 DB (ignore night)
325 td.dirPrice[0].singlePrice = 0;
326 td.dirPrice[0].noDiscount = 1;
329 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(17, 20)), 2, TOLERANCE); // Near 17:30, 0 < 4 NA
330 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(17, 20)), 2, TOLERANCE); // Near 17:30, 6 > 4 NA
331 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(22, 20)), 0, TOLERANCE); // Near 22:30, 0 < 4 DA
332 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(22, 20)), 0, TOLERANCE); // Near 22:30, 6 > 4 DA
334 td.dirPrice[0].singlePrice = 1;
335 td.dirPrice[0].noDiscount = 1;
338 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(17, 20)), 0, TOLERANCE); // Near 17:30, 0 < 4 DA (ignore night)
339 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(17, 20)), 0, TOLERANCE); // Near 17:30, 6 > 4 DA (ignore night)
340 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 0 * 1024 * 1024, 0, makeTime(22, 20)), 0, TOLERANCE); // Near 22:30, 0 < 4 DA (ignore night)
341 BOOST_CHECK_CLOSE(tariff.GetPriceWithTraffType(0, 6 * 1024 * 1024, 0, makeTime(22, 20)), 0, TOLERANCE); // Near 22:30, 6 > 4 DA (ignore night)
344 BOOST_AUTO_TEST_CASE(ChangePolicyAllow)
346 STG::TariffData td("test");
347 td.tariffConf.changePolicy = STG::Tariff::ALLOW;
348 td.tariffConf.fee = 100;
349 const STG::TariffImpl tariff(td);
351 td.tariffConf.fee = 50;
352 const STG::TariffImpl cheaper(td);
354 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), true);
356 td.tariffConf.fee = 100;
357 const STG::TariffImpl equal(td);
359 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(equal, 1461606400).empty(), true);
361 td.tariffConf.fee = 150;
362 const STG::TariffImpl expensive(td);
364 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(expensive, 1461606400).empty(), true);
367 BOOST_AUTO_TEST_CASE(ChangePolicyToCheap)
369 STG::TariffData td("test");
370 td.tariffConf.changePolicy = STG::Tariff::TO_CHEAP;
371 td.tariffConf.fee = 100;
372 const STG::TariffImpl tariff(td);
374 td.tariffConf.fee = 50;
375 const STG::TariffImpl cheaper(td);
377 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), true);
379 td.tariffConf.fee = 100;
380 const STG::TariffImpl equal(td);
382 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(equal, 1461606400).empty(), false);
384 td.tariffConf.fee = 150;
385 const STG::TariffImpl expensive(td);
387 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(expensive, 1461606400).empty(), false);
390 BOOST_AUTO_TEST_CASE(ChangePolicyToExpensive)
392 STG::TariffData td("test");
393 td.tariffConf.changePolicy = STG::Tariff::TO_EXPENSIVE;
394 td.tariffConf.fee = 100;
395 const STG::TariffImpl tariff(td);
397 td.tariffConf.fee = 50;
398 const STG::TariffImpl cheaper(td);
400 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), false);
402 td.tariffConf.fee = 100;
403 const STG::TariffImpl equal(td);
405 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(equal, 1461606400).empty(), true);
407 td.tariffConf.fee = 150;
408 const STG::TariffImpl expensive(td);
410 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(expensive, 1461606400).empty(), true);
413 BOOST_AUTO_TEST_CASE(ChangePolicyDeny)
415 STG::TariffData td("test");
416 td.tariffConf.changePolicy = STG::Tariff::DENY;
417 td.tariffConf.fee = 100;
418 const STG::TariffImpl tariff(td);
420 td.tariffConf.fee = 50;
421 const STG::TariffImpl cheaper(td);
423 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), false);
425 td.tariffConf.fee = 100;
426 const STG::TariffImpl equal(td);
428 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(equal, 1461606400).empty(), false);
430 td.tariffConf.fee = 150;
431 const STG::TariffImpl expensive(td);
433 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(expensive, 1461606400).empty(), false);
436 BOOST_AUTO_TEST_CASE(ChangePolicyTimeoutInThePast)
438 STG::TariffData td("test");
439 td.tariffConf.changePolicyTimeout = 1451606400;
440 td.tariffConf.changePolicy = STG::Tariff::TO_EXPENSIVE;
441 td.tariffConf.fee = 100;
442 const STG::TariffImpl tariff(td);
444 td.tariffConf.fee = 50;
445 const STG::TariffImpl cheaper(td);
447 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), true);
450 BOOST_AUTO_TEST_CASE(ChangePolicyTimeoutInFuture)
452 STG::TariffData td("test");
453 td.tariffConf.changePolicyTimeout = 1483228800;
454 td.tariffConf.changePolicy = STG::Tariff::TO_EXPENSIVE;
455 td.tariffConf.fee = 100;
456 const STG::TariffImpl tariff(td);
458 td.tariffConf.fee = 50;
459 const STG::TariffImpl cheaper(td);
461 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), false);
464 BOOST_AUTO_TEST_CASE(ChangePolicyTimeoutNow)
466 STG::TariffData td("test");
467 td.tariffConf.changePolicyTimeout = 0;
468 td.tariffConf.changePolicy = STG::Tariff::TO_EXPENSIVE;
469 td.tariffConf.fee = 100;
470 const STG::TariffImpl tariff(td);
472 td.tariffConf.fee = 50;
473 const STG::TariffImpl cheaper(td);
475 BOOST_CHECK_EQUAL(tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), false);
478 BOOST_AUTO_TEST_SUITE_END()