mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/calculations] Clean calculation store test
Change-Id: I9fd0d93f9c2f8ba2ba9f0be38b4a0f471eae86b8
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user