Blame view

Giac_maj/epsilon-giac/poincare/test/simplify_utils.cpp 3.08 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  #include <poincare.h>
  #include <assert.h>
  
  using namespace Poincare;
  
  #if POINCARE_TESTS_PRINT_EXPRESSIONS
  #include "../src/expression_debug.h"
  #include <iostream>
  using namespace std;
  #endif
  
  bool simplifies_to(const char * input_string, const char * expected_string) {
  #if POINCARE_TESTS_PRINT_EXPRESSIONS
    cout << "---- Simplification Run ----"  << endl;
    cout << input_string << " -> " << expected_string << endl;
  #endif
    Expression * input = Expression::parse(input_string);
    assert(input != nullptr);
  #if POINCARE_TESTS_PRINT_EXPRESSIONS
    cout << "Input = " << endl;
    print_expression(input);
  #endif
  
    Expression * simplified = input->simplify();
    assert(simplified != nullptr);
  #if POINCARE_TESTS_PRINT_EXPRESSIONS
    cout << "Simplified = " << endl;
    print_expression(simplified);
  #endif
  
    Expression * expected = Expression::parse(expected_string);
    assert(expected != nullptr);
  #if POINCARE_TESTS_PRINT_EXPRESSIONS
    cout << "Expected = " << endl;
    print_expression(expected);
  #endif
  
    bool isIdentical = simplified->isIdenticalTo(expected);
  
    delete expected;
    delete simplified;
    delete input;
  
    return isIdentical;
  }
  
  bool identical_to(const char * input_string, const char * expected_string) {
  #if POINCARE_TESTS_PRINT_EXPRESSIONS
    cout << "---- Identical Run ----"  << endl;
    cout << input_string << " -> " << expected_string << endl;
  #endif
    Expression * input = Expression::parse(input_string);
    assert(input != nullptr);
  #if POINCARE_TESTS_PRINT_EXPRESSIONS
    cout << "Input = " << endl;
    print_expression(input);
  #endif
  
    Expression * expected = Expression::parse(expected_string);
    assert(expected != nullptr);
  #if POINCARE_TESTS_PRINT_EXPRESSIONS
    cout << "Expected = " << endl;
    print_expression(expected);
  #endif
  
    bool isIdentical = input->isIdenticalTo(expected);
  
    delete expected;
    delete input;
  
    return isIdentical;
  }
  
  bool equivalent_to(const char * input_string, const char * expected_string) {
  #if POINCARE_TESTS_PRINT_EXPRESSIONS
    cout << "---- Equivalence Run ----"  << endl;
    cout << input_string << " -> " << expected_string << endl;
  #endif
    Expression * input = Expression::parse(input_string);
    assert(input != nullptr);
  #if POINCARE_TESTS_PRINT_EXPRESSIONS
    cout << "Input = " << endl;
    print_expression(input);
  #endif
  
    Expression * expected = Expression::parse(expected_string);
    assert(expected != nullptr);
  #if POINCARE_TESTS_PRINT_EXPRESSIONS
    cout << "Expected = " << endl;
    print_expression(expected);
  #endif
  
    Expression * simplified_input = input->simplify();
    assert(simplified_input != nullptr);
  #if POINCARE_TESTS_PRINT_EXPRESSIONS
    cout << "Simplified Input = " << endl;
    print_expression(simplified_input);
  #endif
  
    Expression * simplified_expected = Expression::parse(expected_string);
    assert(simplified_expected != nullptr);
  #if POINCARE_TESTS_PRINT_EXPRESSIONS
    cout << "Simplified Expected = " << endl;
    print_expression(simplified_expected);
  #endif
    bool isEquivalent = simplified_input->isIdenticalTo(simplified_expected);
  
    delete expected;
    delete input;
    delete simplified_expected;
    delete simplified_input;
  
    return isEquivalent;
  }