Blame view

Modif/epsilon-master/apps/calculation/test/calculation_store.cpp 2.24 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  #include <quiz.h>
  #include <string.h>
  #include <assert.h>
  #include "../calculation_store.h"
  
  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;
    assert(CalculationStore::k_maxNumberOfCalculations == 10);
    for (int i = 0; i < CalculationStore::k_maxNumberOfCalculations; i++) {
      char text[2] = {(char)(i+'0'), 0};
      store.push(text, &globalContext);
      assert(store.numberOfCalculations() == i+1);
    }
    /* Store is now {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} */
    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} */
    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 {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);
  
    store.deleteAll();
    store.push("1+3/4", &globalContext);
    store.push("ans+2/3", &globalContext);
    ::Calculation::Calculation * lastCalculation = store.calculationAtIndex(1);
    assert(lastCalculation->shouldOnlyDisplayApproximateOutput(&globalContext) == false);
    assert(strcmp(lastCalculation->exactOutputText(),"29/12") == 0);
  
    store.push("ans+0.22", &globalContext);
    lastCalculation = store.calculationAtIndex(2);
    assert(lastCalculation->shouldOnlyDisplayApproximateOutput(&globalContext) == true);
    assert(strcmp(lastCalculation->approximateOutputText(),"2.6366666666667") == 0);
  }