X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/2d09f6a7afb3481586a9471b0cde35aac271ce9d..c02633d77cb05a5deb05440d77b12ccc5bc19b85:/tests/test_fee_charge_rules.cpp diff --git a/tests/test_fee_charge_rules.cpp b/tests/test_fee_charge_rules.cpp index 0b55e5de..1fe1542f 100644 --- a/tests/test_fee_charge_rules.cpp +++ b/tests/test_fee_charge_rules.cpp @@ -1,12 +1,13 @@ #include "tut/tut.hpp" +#include "stg/admin.h" #include "stg/user_property.h" #include "user_impl.h" #include "testsettings.h" #include "testtariffs.h" -#include "testadmin.h" #include "teststore.h" +#include "testservices.h" namespace tut { @@ -38,26 +39,29 @@ namespace tut TEST_SETTINGS_LOCAL settings(0); TEST_TARIFFS tariffs; - TEST_ADMIN admin; + STG::Admin admin(STG::Priv(0xFFFF), {}, {}); TEST_STORE store; - USER_IMPL user(&settings, &store, &tariffs, &admin, NULL); + TEST_SERVICES services; + STG::UserImpl user(&settings, &store, &tariffs, &admin, NULL, services); - USER_PROPERTY & cash(user.GetProperty().cash); - USER_PROPERTY & tariffName(user.GetProperty().tariffName); + STG::UserProperty & cash(user.GetProperties().cash); + STG::UserProperty & tariffName(user.GetProperties().tariffName); - ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + ensure_equals("user.cash == 0 (initial value)", user.GetProperties().cash, 0); cash = 100; - ensure_equals("user.cash == 100", user.GetProperty().cash, 100); + ensure_equals("user.cash == 100 (explicitly set)", user.GetProperties().cash, 100); tariffs.SetFee(50); tariffName = "test"; - ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test"); + ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperties().tariffName.ConstData(), "test"); user.ProcessDayFee(); - ensure_equals("user.cash == 50", user.GetProperty().cash, 50); + ensure_equals("user.cash == 50 (first fee charge)", user.GetProperties().cash, 50); user.ProcessDayFee(); - ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + ensure_equals("user.cash == 0 (second fee charge)", user.GetProperties().cash, 0); user.ProcessDayFee(); - ensure_equals("user.cash == -50", user.GetProperty().cash, -50); + ensure_equals("user.cash == -50 (third fee charge)", user.GetProperties().cash, -50); + user.ProcessDayFee(); + ensure_equals("user.cash == -100 (fourth fee charge)", user.GetProperties().cash, -100); } template<> @@ -68,30 +72,43 @@ namespace tut TEST_SETTINGS_LOCAL settings(1); TEST_TARIFFS tariffs; - TEST_ADMIN admin; + STG::Admin admin(STG::Priv(0xFFFF), {}, {}); TEST_STORE store; - USER_IMPL user(&settings, &store, &tariffs, &admin, NULL); + TEST_SERVICES services; + STG::UserImpl user(&settings, &store, &tariffs, &admin, NULL, services); - USER_PROPERTY & cash(user.GetProperty().cash); - USER_PROPERTY & tariffName(user.GetProperty().tariffName); + STG::UserProperty & cash(user.GetProperties().cash); + STG::UserProperty & credit(user.GetProperties().credit); + STG::UserProperty & tariffName(user.GetProperties().tariffName); - ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + ensure_equals("user.cash == 0 (initial value)", user.GetProperties().cash, 0); + ensure_equals("user.credit == 0 (initial value)", user.GetProperties().credit, 0); cash = 100; - ensure_equals("user.cash == 100", user.GetProperty().cash, 100); + ensure_equals("user.cash == 100 (explicitly set)", user.GetProperties().cash, 100); tariffs.SetFee(50); tariffName = "test"; - ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test"); + ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperties().tariffName.ConstData(), "test"); + user.ProcessDayFee(); + ensure_equals("user.cash == 50 (first fee charge)", user.GetProperties().cash, 50); user.ProcessDayFee(); - ensure_equals("user.cash == 50", user.GetProperty().cash, 50); + ensure_equals("user.cash == 0 (second fee charge)", user.GetProperties().cash, 0); user.ProcessDayFee(); - ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + ensure_equals("user.cash == -50 (third fee charge)", user.GetProperties().cash, -50); user.ProcessDayFee(); - ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + ensure_equals("user.cash == -50 (not charging `cause value is negative)", user.GetProperties().cash, -50); cash = 49; - ensure_equals("user.cash == 49", user.GetProperty().cash, 49); + ensure_equals("user.cash == 49 (explicitly set)", user.GetProperties().cash, 49); + user.ProcessDayFee(); + ensure_equals("user.cash == -1 (charge to negative value)", user.GetProperties().cash, -1); + user.ProcessDayFee(); + ensure_equals("user.cash == -1 (not charging `cause value is negative)", user.GetProperties().cash, -1); + credit = 50; + ensure_equals("user.credit == 50 (explicitly set)", user.GetProperties().credit, 50); user.ProcessDayFee(); - ensure_equals("user.cash == -1", user.GetProperty().cash, -1); + ensure_equals("user.cash == -51 (charging `cause value + credit gives us a positive value)", user.GetProperties().cash, -51); + user.ProcessDayFee(); + ensure_equals("user.cash == -51 (not charging `cause credit now is not enoght)", user.GetProperties().cash, -51); } template<> @@ -102,30 +119,40 @@ namespace tut TEST_SETTINGS_LOCAL settings(2); TEST_TARIFFS tariffs; - TEST_ADMIN admin; + STG::Admin admin(STG::Priv(0xFFFF), {}, {}); TEST_STORE store; - USER_IMPL user(&settings, &store, &tariffs, &admin, NULL); + TEST_SERVICES services; + STG::UserImpl user(&settings, &store, &tariffs, &admin, NULL, services); - USER_PROPERTY & cash(user.GetProperty().cash); - USER_PROPERTY & tariffName(user.GetProperty().tariffName); + STG::UserProperty & cash(user.GetProperties().cash); + STG::UserProperty & credit(user.GetProperties().credit); + STG::UserProperty & tariffName(user.GetProperties().tariffName); - ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + ensure_equals("user.cash == 0 (initial value)", user.GetProperties().cash, 0); cash = 100; - ensure_equals("user.cash == 100", user.GetProperty().cash, 100); + ensure_equals("user.cash == 100 (explicitly set)", user.GetProperties().cash, 100); tariffs.SetFee(50); tariffName = "test"; - ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test"); + ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperties().tariffName.ConstData(), "test"); + user.ProcessDayFee(); + ensure_equals("user.cash == 50 (first fee charge)", user.GetProperties().cash, 50); user.ProcessDayFee(); - ensure_equals("user.cash == 50", user.GetProperty().cash, 50); + ensure_equals("user.cash == 0 (second fee charge)", user.GetProperties().cash, 0); user.ProcessDayFee(); - ensure_equals("user.cash == 50", user.GetProperty().cash, 50); - tariffs.SetFee(49); + ensure_equals("user.cash == 0 (not charging `cause value is lower than fee)", user.GetProperties().cash, 0); + cash = 50; + ensure_equals("user.cash == 50 (explicitly set)", user.GetProperties().cash, 50); + tariffs.SetFee(51); user.ProcessDayFee(); - ensure_equals("user.cash == 1", user.GetProperty().cash, 1); + ensure_equals("user.cash == 50 (not charging `cause value is lower than fee)", user.GetProperties().cash, 50); cash = 0; - ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + ensure_equals("user.cash == 0 (explicitly set)", user.GetProperties().cash, 0); + credit = 51; + ensure_equals("user.credit == 51 (explicitly set)", user.GetProperties().credit, 51); + user.ProcessDayFee(); + ensure_equals("user.cash == -51 (charging `cause value + credit gives us a value greater than fee)", user.GetProperties().cash, -51); user.ProcessDayFee(); - ensure_equals("user.cash == 0", user.GetProperty().cash, 0); + ensure_equals("user.cash == -51 (not charging `cause credit now is not enought)", user.GetProperties().cash, -51); } }