X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/77aa0c79adcc95d641fd17a246cfebf0eba56bd0..a84a49ca1eb7c31f79f6328e9dc453399ee120f9:/tests/test_tariff.cpp?ds=inline diff --git a/tests/test_tariff.cpp b/tests/test_tariff.cpp index 188785c7..9565be68 100644 --- a/tests/test_tariff.cpp +++ b/tests/test_tariff.cpp @@ -352,24 +352,24 @@ namespace tut set_test_name("Check changePolicy - ALLOW"); TARIFF_DATA td("test"); - td.tariffConf.changePolicy = TARIFF::CHANGE_POLICY ALLOW; + td.tariffConf.changePolicy = TARIFF::ALLOW; td.tariffConf.fee = 100; TARIFF_IMPL tariff(td); td.tariffConf.fee = 50; TARIFF_IMPL cheaper(td); - ensure_equals("Allow cheaper", tariff.TariffChangeIsAllowed(cheaper).empty(), true); + ensure_equals("Allow cheaper", tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), true); td.tariffConf.fee = 100; - TARIFF_IMPL equals(td); + TARIFF_IMPL equal(td); - ensure_equals("Allow equal", tariff.TariffChangeIsAllowed(equal).empty(), true); + ensure_equals("Allow equal", tariff.TariffChangeIsAllowed(equal, 1461606400).empty(), true); td.tariffConf.fee = 150; TARIFF_IMPL expensive(td); - ensure_equals("Allow expensive", tariff.TariffChangeIsAllowed(expensive).empty(), true); + ensure_equals("Allow expensive", tariff.TariffChangeIsAllowed(expensive, 1461606400).empty(), true); } template<> @@ -379,23 +379,131 @@ namespace tut set_test_name("Check changePolicy - TO_CHEAP"); TARIFF_DATA td("test"); - td.tariffConf.changePolicy = TARIFF::CHANGE_POLICY TO_CHEAP; + td.tariffConf.changePolicy = TARIFF::TO_CHEAP; td.tariffConf.fee = 100; TARIFF_IMPL tariff(td); td.tariffConf.fee = 50; TARIFF_IMPL cheaper(td); - ensure_equals("Allow cheaper", tariff.TariffChangeIsAllowed(cheaper).empty(), true); + ensure_equals("Allow cheaper", tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), true); td.tariffConf.fee = 100; - TARIFF_IMPL equals(td); + TARIFF_IMPL equal(td); - ensure_equals("Allow equal", !tariff.TariffChangeIsAllowed(equal).empty(), true); + ensure_equals("Prohibit equal", tariff.TariffChangeIsAllowed(equal, 1461606400).empty(), false); td.tariffConf.fee = 150; TARIFF_IMPL expensive(td); - ensure_equals("Allow expensive", !tariff.TariffChangeIsAllowed(expensive).empty(), true); + ensure_equals("Prohibit expensive", tariff.TariffChangeIsAllowed(expensive, 1461606400).empty(), false); + } + + template<> + template<> + void testobject::test<9>() + { + set_test_name("Check changePolicy - TO_EXPENSIVE"); + + TARIFF_DATA td("test"); + td.tariffConf.changePolicy = TARIFF::TO_EXPENSIVE; + td.tariffConf.fee = 100; + TARIFF_IMPL tariff(td); + + td.tariffConf.fee = 50; + TARIFF_IMPL cheaper(td); + + ensure_equals("Prohibit cheaper", tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), false); + + td.tariffConf.fee = 100; + TARIFF_IMPL equal(td); + + ensure_equals("Allow equal", tariff.TariffChangeIsAllowed(equal, 1461606400).empty(), true); + + td.tariffConf.fee = 150; + TARIFF_IMPL expensive(td); + + ensure_equals("Allow expensive", tariff.TariffChangeIsAllowed(expensive, 1461606400).empty(), true); + } + + template<> + template<> + void testobject::test<10>() + { + set_test_name("Check changePolicy - DENY"); + + TARIFF_DATA td("test"); + td.tariffConf.changePolicy = TARIFF::DENY; + td.tariffConf.fee = 100; + TARIFF_IMPL tariff(td); + + td.tariffConf.fee = 50; + TARIFF_IMPL cheaper(td); + + ensure_equals("Prohibit cheaper", tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), false); + + td.tariffConf.fee = 100; + TARIFF_IMPL equal(td); + + ensure_equals("Prohibit equal", tariff.TariffChangeIsAllowed(equal, 1461606400).empty(), false); + + td.tariffConf.fee = 150; + TARIFF_IMPL expensive(td); + + ensure_equals("Prohibit expensive", tariff.TariffChangeIsAllowed(expensive, 1461606400).empty(), false); + } + + template<> + template<> + void testobject::test<11>() + { + set_test_name("Check changePolicyTimeout < current time"); + + TARIFF_DATA td("test"); + td.tariffConf.changePolicyTimeout = 1451606400; + td.tariffConf.changePolicy = TARIFF::TO_EXPENSIVE; + td.tariffConf.fee = 100; + TARIFF_IMPL tariff(td); + + td.tariffConf.fee = 50; + TARIFF_IMPL cheaper(td); + + ensure_equals("Allow cheaper", tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), true); + } + + template<> + template<> + void testobject::test<12>() + { + set_test_name("Check changePolicyTimeout > current time"); + + TARIFF_DATA td("test"); + td.tariffConf.changePolicyTimeout = 1483228800; + td.tariffConf.changePolicy = TARIFF::TO_EXPENSIVE; + td.tariffConf.fee = 100; + TARIFF_IMPL tariff(td); + + td.tariffConf.fee = 50; + TARIFF_IMPL cheaper(td); + + ensure_equals("Prohibit cheaper", tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), false); + } + + template<> + template<> + void testobject::test<13>() + { + set_test_name("Check changePolicyTimeout = 0"); + + TARIFF_DATA td("test"); + td.tariffConf.changePolicyTimeout = 0; + td.tariffConf.changePolicy = TARIFF::TO_EXPENSIVE; + td.tariffConf.fee = 100; + TARIFF_IMPL tariff(td); + + td.tariffConf.fee = 50; + TARIFF_IMPL cheaper(td); + + ensure_equals("Prohibit cheaper", tariff.TariffChangeIsAllowed(cheaper, 1461606400).empty(), false); } }