]> git.stg.codes - stg.git/blobdiff - tests/test_fee_charge_rules.cpp
Remove TravisCI file as well.
[stg.git] / tests / test_fee_charge_rules.cpp
index 657a609ae036c9264e64201ea0d61957b4d198d1..2df09be425dd6c530430a06ed9ec458e328129ac 100644 (file)
@@ -7,8 +7,7 @@
 #include "testtariffs.h"
 #include "testadmin.h"
 #include "teststore.h"
 #include "testtariffs.h"
 #include "testadmin.h"
 #include "teststore.h"
-
-const volatile time_t stgTime = 0;
+#include "testservices.h"
 
 namespace tut
 {
 
 namespace tut
 {
@@ -42,24 +41,27 @@ namespace tut
         TEST_TARIFFS tariffs;
         TEST_ADMIN admin;
         TEST_STORE store;
         TEST_TARIFFS tariffs;
         TEST_ADMIN admin;
         TEST_STORE store;
-        USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
+        TEST_SERVICES services;
+        USER_IMPL user(&settings, &store, &tariffs, &admin, NULL, services);
 
         USER_PROPERTY<double> & cash(user.GetProperty().cash);
         USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
 
 
         USER_PROPERTY<double> & cash(user.GetProperty().cash);
         USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
 
-        ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
+        ensure_equals("user.cash == 0 (initial value)", user.GetProperty().cash, 0);
         cash = 100;
         cash = 100;
-        ensure_equals("user.cash == 100", user.GetProperty().cash, 100);
+        ensure_equals("user.cash == 100 (explicitly set)", user.GetProperty().cash, 100);
 
         tariffs.SetFee(50);
         tariffName = "test";
 
         tariffs.SetFee(50);
         tariffName = "test";
-        ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
+        ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperty().tariffName.ConstData(), "test");
+        user.ProcessDayFee();
+        ensure_equals("user.cash == 50 (first fee charge)", user.GetProperty().cash, 50);
         user.ProcessDayFee();
         user.ProcessDayFee();
-        ensure_equals("user.cash == 50", user.GetProperty().cash, 50);
+        ensure_equals("user.cash == 0 (second fee charge)", user.GetProperty().cash, 0);
         user.ProcessDayFee();
         user.ProcessDayFee();
-        ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
+        ensure_equals("user.cash == -50 (third fee charge)", user.GetProperty().cash, -50);
         user.ProcessDayFee();
         user.ProcessDayFee();
-        ensure_equals("user.cash == -50", user.GetProperty().cash, -50);
+        ensure_equals("user.cash == -100 (fourth fee charge)", user.GetProperty().cash, -100);
     }
 
     template<>
     }
 
     template<>
@@ -72,28 +74,41 @@ namespace tut
         TEST_TARIFFS tariffs;
         TEST_ADMIN admin;
         TEST_STORE store;
         TEST_TARIFFS tariffs;
         TEST_ADMIN admin;
         TEST_STORE store;
-        USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
+        TEST_SERVICES services;
+        USER_IMPL user(&settings, &store, &tariffs, &admin, NULL, services);
 
         USER_PROPERTY<double> & cash(user.GetProperty().cash);
 
         USER_PROPERTY<double> & cash(user.GetProperty().cash);
+        USER_PROPERTY<double> & credit(user.GetProperty().credit);
         USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
 
         USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
 
-        ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
+        ensure_equals("user.cash == 0 (initial value)", user.GetProperty().cash, 0);
+        ensure_equals("user.credit == 0 (initial value)", user.GetProperty().credit, 0);
         cash = 100;
         cash = 100;
-        ensure_equals("user.cash == 100", user.GetProperty().cash, 100);
+        ensure_equals("user.cash == 100 (explicitly set)", user.GetProperty().cash, 100);
 
         tariffs.SetFee(50);
         tariffName = "test";
 
         tariffs.SetFee(50);
         tariffName = "test";
-        ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
+        ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperty().tariffName.ConstData(), "test");
         user.ProcessDayFee();
         user.ProcessDayFee();
-        ensure_equals("user.cash == 50", user.GetProperty().cash, 50);
+        ensure_equals("user.cash == 50 (first fee charge)", user.GetProperty().cash, 50);
         user.ProcessDayFee();
         user.ProcessDayFee();
-        ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
+        ensure_equals("user.cash == 0 (second fee charge)", user.GetProperty().cash, 0);
         user.ProcessDayFee();
         user.ProcessDayFee();
-        ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
+        ensure_equals("user.cash == -50 (third fee charge)", user.GetProperty().cash, -50);
+        user.ProcessDayFee();
+        ensure_equals("user.cash == -50 (not charging `cause value is negative)", user.GetProperty().cash, -50);
         cash = 49;
         cash = 49;
-        ensure_equals("user.cash == 49", user.GetProperty().cash, 49);
+        ensure_equals("user.cash == 49 (explicitly set)", user.GetProperty().cash, 49);
+        user.ProcessDayFee();
+        ensure_equals("user.cash == -1 (charge to negative value)", user.GetProperty().cash, -1);
         user.ProcessDayFee();
         user.ProcessDayFee();
-        ensure_equals("user.cash == -1", user.GetProperty().cash, -1);
+        ensure_equals("user.cash == -1 (not charging `cause value is negative)", user.GetProperty().cash, -1);
+        credit = 50;
+        ensure_equals("user.credit == 50 (explicitly set)", user.GetProperty().credit, 50);
+        user.ProcessDayFee();
+        ensure_equals("user.cash == -51 (charging `cause value + credit gives us a positive value)", user.GetProperty().cash, -51);
+        user.ProcessDayFee();
+        ensure_equals("user.cash == -51 (not charging `cause credit now is not enoght)", user.GetProperty().cash, -51);
     }
 
     template<>
     }
 
     template<>
@@ -106,28 +121,38 @@ namespace tut
         TEST_TARIFFS tariffs;
         TEST_ADMIN admin;
         TEST_STORE store;
         TEST_TARIFFS tariffs;
         TEST_ADMIN admin;
         TEST_STORE store;
-        USER_IMPL user(&settings, &store, &tariffs, &admin, NULL);
+        TEST_SERVICES services;
+        USER_IMPL user(&settings, &store, &tariffs, &admin, NULL, services);
 
         USER_PROPERTY<double> & cash(user.GetProperty().cash);
 
         USER_PROPERTY<double> & cash(user.GetProperty().cash);
+        USER_PROPERTY<double> & credit(user.GetProperty().credit);
         USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
 
         USER_PROPERTY<std::string> & tariffName(user.GetProperty().tariffName);
 
-        ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
+        ensure_equals("user.cash == 0 (initial value)", user.GetProperty().cash, 0);
         cash = 100;
         cash = 100;
-        ensure_equals("user.cash == 100", user.GetProperty().cash, 100);
+        ensure_equals("user.cash == 100 (explicitly set)", user.GetProperty().cash, 100);
 
         tariffs.SetFee(50);
         tariffName = "test";
 
         tariffs.SetFee(50);
         tariffName = "test";
-        ensure_equals("user.tariffName == 'test'", user.GetProperty().tariffName.ConstData(), "test");
+        ensure_equals("user.tariffName == 'test' (explicitly set)", user.GetProperty().tariffName.ConstData(), "test");
         user.ProcessDayFee();
         user.ProcessDayFee();
-        ensure_equals("user.cash == 50", user.GetProperty().cash, 50);
+        ensure_equals("user.cash == 50 (first fee charge)", user.GetProperty().cash, 50);
         user.ProcessDayFee();
         user.ProcessDayFee();
-        ensure_equals("user.cash == 50", user.GetProperty().cash, 50);
-        tariffs.SetFee(49);
+        ensure_equals("user.cash == 0 (second fee charge)", user.GetProperty().cash, 0);
         user.ProcessDayFee();
         user.ProcessDayFee();
-        ensure_equals("user.cash == 1", user.GetProperty().cash, 1);
+        ensure_equals("user.cash == 0 (not charging `cause value is lower than fee)", user.GetProperty().cash, 0);
+        cash = 50;
+        ensure_equals("user.cash == 50 (explicitly set)", user.GetProperty().cash, 50);
+        tariffs.SetFee(51);
+        user.ProcessDayFee();
+        ensure_equals("user.cash == 50 (not charging `cause value is lower than fee)", user.GetProperty().cash, 50);
         cash = 0;
         cash = 0;
-        ensure_equals("user.cash == 0", user.GetProperty().cash, 0);
+        ensure_equals("user.cash == 0 (explicitly set)", user.GetProperty().cash, 0);
+        credit = 51;
+        ensure_equals("user.credit == 51 (explicitly set)", user.GetProperty().credit, 51);
+        user.ProcessDayFee();
+        ensure_equals("user.cash == -51 (charging `cause value + credit gives us a value greater than fee)", user.GetProperty().cash, -51);
         user.ProcessDayFee();
         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.GetProperty().cash, -51);
     }
 }
     }
 }