From df59cd6ef72cffef8957a6a4f63e3613ffc2daa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 31 May 2017 13:55:51 +0200 Subject: [PATCH] [apps/calculations] Clean calculation store test Change-Id: I9fd0d93f9c2f8ba2ba9f0be38b4a0f471eae86b8 --- apps/calculation/test/calculation_store.cpp | 33 +++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/apps/calculation/test/calculation_store.cpp b/apps/calculation/test/calculation_store.cpp index c581ecf08..aae3cfc8b 100644 --- a/apps/calculation/test/calculation_store.cpp +++ b/apps/calculation/test/calculation_store.cpp @@ -6,6 +6,12 @@ using namespace Poincare; using namespace Calculation; +void assert_store_is(CalculationStore * store, const char * result[10]) { + for (int i = 0; i < store->numberOfCalculations(); i++) { + assert(strcmp(store->calculationAtIndex(i)->inputText(), result[i]) == 0); + } +} + QUIZ_CASE(calculation_store) { GlobalContext globalContext; CalculationStore store; @@ -16,30 +22,27 @@ QUIZ_CASE(calculation_store) { assert(store.numberOfCalculations() == i+1); } /* Store is now {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} */ - for (int i = 0; i < CalculationStore::k_maxNumberOfCalculations; i++) { - assert(store.calculationAtIndex(i)->input()->approximate(globalContext) == i); - } + const char * result[10] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; + assert_store_is(&store, result); + store.push("10", &globalContext); /* Store is now {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} */ - assert(store.calculationAtIndex(9)->input()->approximate(globalContext) == 10); - assert(store.calculationAtIndex(0)->input()->approximate(globalContext) == 1); - for (int i = 0; i < CalculationStore::k_maxNumberOfCalculations; i++) { - char text[2] = {(char)(i+'0'), 0}; - store.push(text, &globalContext); - assert(store.numberOfCalculations() == 10); - } - /* Store is now {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} */ + const char * result1[10] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; + assert_store_is(&store, result1); + for (int i = 9; i > 0; i = i-2) { store.deleteCalculationAtIndex(i); } - /* Store is now {0, 2, 4, 6, 8} */ - for (int i = 0; i < 5; i++) { - assert(store.calculationAtIndex(i)->input()->approximate(globalContext) == 2.0f*i); - } + /* Store is now {1, 3, 5, 7, 9} */ + const char * result2[10] = {"1", "3", "5", "7", "9", "", "", "", "", ""}; + assert_store_is(&store, result2); + for (int i = 5; i < CalculationStore::k_maxNumberOfCalculations; i++) { char text[3] = {(char)(i+'0'), 0}; store.push(text, &globalContext); assert(store.numberOfCalculations() == i+1); } /* Store is now {0, 2, 4, 6, 8, 5, 6, 7, 8, 9} */ + const char * result3[10] = {"1", "3", "5", "7", "9", "5", "6", "7", "8", "9"}; + assert_store_is(&store, result3); }