From 21c054c70c5ad524a0e42ce0e644d9058ee2d020 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 20 Oct 2011 13:52:37 +0300 Subject: [PATCH] Add tests for fee charge rules with non-zero credit --- tests/test_fee_charge_rules.cpp | 66 ++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/tests/test_fee_charge_rules.cpp b/tests/test_fee_charge_rules.cpp index dfe7e850..825c2b36 100644 --- a/tests/test_fee_charge_rules.cpp +++ b/tests/test_fee_charge_rules.cpp @@ -45,19 +45,21 @@ namespace tut USER_PROPERTY & cash(user.GetProperty().cash); USER_PROPERTY & 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; - 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"; - 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", user.GetProperty().cash, 50); + ensure_equals("user.cash == 50 (first fee charge)", user.GetProperty().cash, 50); 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(); - ensure_equals("user.cash == -50", user.GetProperty().cash, -50); + ensure_equals("user.cash == -50 (third fee charge)", user.GetProperty().cash, -50); + user.ProcessDayFee(); + ensure_equals("user.cash == -100 (fourth fee charge)", user.GetProperty().cash, -100); } template<> @@ -73,25 +75,37 @@ namespace tut USER_IMPL user(&settings, &store, &tariffs, &admin, NULL); USER_PROPERTY & cash(user.GetProperty().cash); + USER_PROPERTY & credit(user.GetProperty().credit); USER_PROPERTY & 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; - 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"; - 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(); - ensure_equals("user.cash == 50", user.GetProperty().cash, 50); + ensure_equals("user.cash == 0 (second fee charge)", user.GetProperty().cash, 0); 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 == 0", user.GetProperty().cash, -50); + ensure_equals("user.cash == -50 (not charging `cause value is negative)", user.GetProperty().cash, -50); 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(); + 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 == -1", user.GetProperty().cash, -1); + 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<> @@ -107,26 +121,34 @@ namespace tut USER_IMPL user(&settings, &store, &tariffs, &admin, NULL); USER_PROPERTY & cash(user.GetProperty().cash); + USER_PROPERTY & credit(user.GetProperty().credit); USER_PROPERTY & 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; - 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"; - 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(); - ensure_equals("user.cash == 50", user.GetProperty().cash, 50); + ensure_equals("user.cash == 0 (second fee charge)", user.GetProperty().cash, 0); user.ProcessDayFee(); - ensure_equals("user.cash == 50", user.GetProperty().cash, 0); + 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", user.GetProperty().cash, 50); + ensure_equals("user.cash == 50 (not charging `cause value is lower than fee)", user.GetProperty().cash, 50); 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(); - 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); } } -- 2.44.2