mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
Add is_identical_to util in tests.
Change-Id: I8b55a228e1bd27e4c7b72891ff887bdc15b02fad
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
#include <assert.h>
|
||||
#include <quiz.h>
|
||||
#include "simplify_utils.h"
|
||||
|
||||
QUIZ_CASE(poincare_simplify_addition_integer) {
|
||||
assert_simplifies_to("1", "1");
|
||||
assert_simplifies_to("1+2", "3");
|
||||
assert_simplifies_to("1+a", "1+a");
|
||||
assert_simplifies_to("1+2+3+4+5+6+7", "28");
|
||||
assert_simplifies_to("1+2+3+4+5+a+6+7", "28+a");
|
||||
assert_simplifies_to("a*(0+0)", "0");
|
||||
assert(simplifies_to("1", "1"));
|
||||
assert(simplifies_to("1+2", "3"));
|
||||
assert(simplifies_to("1+a", "1+a"));
|
||||
assert(simplifies_to("1+2+3+4+5+6+7", "28"));
|
||||
assert(simplifies_to("1+2+3+4+5+a+6+7", "28+a"));
|
||||
assert(simplifies_to("a*(0+0)", "0"));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include <assert.h>
|
||||
#include <quiz.h>
|
||||
#include "simplify_utils.h"
|
||||
|
||||
QUIZ_CASE(poincare_simplify_product_by_zero) {
|
||||
assert_simplifies_to("3*0", "0");
|
||||
assert_simplifies_to("foo*0", "0");
|
||||
assert_simplifies_to("0*3", "0");
|
||||
assert_simplifies_to("0*foo", "0");
|
||||
assert(simplifies_to("3*0", "0"));
|
||||
assert(simplifies_to("foo*0", "0"));
|
||||
assert(simplifies_to("0*3", "0"));
|
||||
assert(simplifies_to("0*foo", "0"));
|
||||
}
|
||||
|
||||
@@ -7,13 +7,11 @@
|
||||
using namespace std;
|
||||
#endif
|
||||
|
||||
void assert_simplifies_to(const char * input_string, const char * expected_string) {
|
||||
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* tab[3] = {new Integer(1), new Integer(2), new Integer(3)};
|
||||
//Expression* input = new Addition(tab, 3, false);
|
||||
Expression * input = Expression::parse(input_string);
|
||||
assert(input != nullptr);
|
||||
#if POINCARE_TESTS_PRINT_EXPRESSIONS
|
||||
@@ -35,10 +33,34 @@ void assert_simplifies_to(const char * input_string, const char * expected_strin
|
||||
print_expression(expected);
|
||||
#endif
|
||||
|
||||
assert(simplified->isIdenticalTo(expected));
|
||||
bool isIdentical = simplified->isIdenticalTo(expected);
|
||||
|
||||
delete expected;
|
||||
if (simplified != input) {
|
||||
delete simplified;
|
||||
}
|
||||
delete simplified;
|
||||
delete input;
|
||||
|
||||
return isIdentical;
|
||||
}
|
||||
|
||||
bool identical_to(const char * input_string, const char * expected_string) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef POINCARE_TEST_SIMPLIFY_UTILS_H
|
||||
#define POINCARE_TEST_SIMPLIFY_UTILS_H
|
||||
|
||||
void assert_simplifies_to(const char * input_string, const char * expected_string);
|
||||
/* Tests that the first expression simplifies to the second. */
|
||||
bool simplifies_to(const char * input_string, const char * expected_string);
|
||||
|
||||
/* Tests that the first expression is identical to the second. */
|
||||
bool identical_to(const char * input_string, const char * expected_string);
|
||||
|
||||
#endif // POINCARE_TEST_SIMPLIFY_UTILS_H
|
||||
|
||||
Reference in New Issue
Block a user