From 60656f3ecd285fbd68d8b25d9cb1ba5f974e0e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Thu, 8 Nov 2018 18:02:58 +0100 Subject: [PATCH] [poincare] Add tests on circular variables definitions --- poincare/test/helper.cpp | 13 +++++++- poincare/test/helper.h | 1 + poincare/test/store.cpp | 65 +++++++++++++++++++++++++++++++++++++++- quiz/src/runner.cpp | 2 +- 4 files changed, 78 insertions(+), 3 deletions(-) diff --git a/poincare/test/helper.cpp b/poincare/test/helper.cpp index 9ef5a106a..ed48fc70f 100644 --- a/poincare/test/helper.cpp +++ b/poincare/test/helper.cpp @@ -98,8 +98,19 @@ void assert_parsed_expression_is(const char * expression, Poincare::Expression r void assert_parsed_expression_polynomial_degree(const char * expression, int degree, const char * symbolName) { Shared::GlobalContext globalContext; Expression e = parse_expression(expression); + Expression result = e.clone().simplify(globalContext, Radian); + if (result.isUninitialized()) { + result = e; + } + quiz_assert(result.polynomialDegree(globalContext, symbolName) == degree); +} + +void assert_simplify(const char * expression) { + Shared::GlobalContext globalContext; + Expression e = parse_expression(expression); + quiz_assert(!e.isUninitialized()); e = e.simplify(globalContext, Radian); - quiz_assert(e.polynomialDegree(globalContext, symbolName) == degree); + quiz_assert(!e.isUninitialized()); } typedef Expression (*ProcessExpression)(Expression, Context & context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat); diff --git a/poincare/test/helper.h b/poincare/test/helper.h index e9befed7d..e1c04315b 100644 --- a/poincare/test/helper.h +++ b/poincare/test/helper.h @@ -22,6 +22,7 @@ void assert_expression_not_parsable(const char * expression); void assert_parsed_expression_type(const char * expression, Poincare::ExpressionNode::Type type); void assert_parsed_expression_is(const char * expression, Poincare::Expression r); void assert_parsed_expression_polynomial_degree(const char * expression, int degree, const char * symbolName = "x"); +void assert_simplify(const char * expression); template void assert_parsed_expression_evaluates_to(const char * expression, const char * approximation, Poincare::Preferences::AngleUnit angleUnit = Degree, Poincare::Preferences::ComplexFormat complexFormat = Cartesian, int numberOfSignificantDigits = -1); diff --git a/poincare/test/store.cpp b/poincare/test/store.cpp index f0e858f3c..ba355bffc 100644 --- a/poincare/test/store.cpp +++ b/poincare/test/store.cpp @@ -77,8 +77,71 @@ QUIZ_CASE(poincare_store_overwrite) { assert_parsed_expression_simplify_to("2>g", "2"); assert_parsed_expression_evaluates_to("g(4)", "undef"); assert_parsed_expression_evaluates_to("f(4)", "undef"); - // Clean the storage for other tests Ion::Storage::sharedStorage()->recordNamed("f.func").destroy(); Ion::Storage::sharedStorage()->recordNamed("g.exp").destroy(); } + +QUIZ_CASE(poincare_store_2_circular_variables) { + assert_simplify("a>b"); + assert_simplify("b>a"); + assert_parsed_expression_evaluates_to("a", "undef"); + assert_parsed_expression_evaluates_to("b", "undef"); + + // Clean the storage for other tests + Ion::Storage::sharedStorage()->recordNamed("a.exp").destroy(); + Ion::Storage::sharedStorage()->recordNamed("b.exp").destroy(); +} + +QUIZ_CASE(poincare_store_3_circular_variables) { + assert_simplify("a>b"); + assert_simplify("b>c"); + assert_simplify("c>a"); + assert_parsed_expression_evaluates_to("a", "undef"); + assert_parsed_expression_evaluates_to("b", "undef"); + assert_parsed_expression_evaluates_to("c", "undef"); + + // Clean the storage for other tests + Ion::Storage::sharedStorage()->recordNamed("a.exp").destroy(); + Ion::Storage::sharedStorage()->recordNamed("b.exp").destroy(); + Ion::Storage::sharedStorage()->recordNamed("c.exp").destroy(); +} + +QUIZ_CASE(poincare_store_2_circular_functions) { + assert_simplify("f(x)>g(x)"); + assert_simplify("g(x)>f(x)"); + assert_parsed_expression_evaluates_to("f(1)", "undef"); + assert_parsed_expression_evaluates_to("g(1)", "undef"); + + // Clean the storage for other tests + Ion::Storage::sharedStorage()->recordNamed("f.func").destroy(); + Ion::Storage::sharedStorage()->recordNamed("g.func").destroy(); +} + +QUIZ_CASE(poincare_store_3_circular_functions) { + assert_simplify("f(x)>g(x)"); + assert_simplify("g(x)>h(x)"); + assert_simplify("h(x)>f(x)"); + assert_parsed_expression_evaluates_to("f(1)", "undef"); + assert_parsed_expression_evaluates_to("g(1)", "undef"); + assert_parsed_expression_evaluates_to("h(1)", "undef"); + + // Clean the storage for other tests + Ion::Storage::sharedStorage()->recordNamed("f.func").destroy(); + Ion::Storage::sharedStorage()->recordNamed("g.func").destroy(); + Ion::Storage::sharedStorage()->recordNamed("h.func").destroy(); +} + +QUIZ_CASE(poincare_store_circular_variables_and_functions) { + assert_simplify("a>b"); + assert_simplify("b>a"); + assert_simplify("a>f(x)"); + assert_parsed_expression_evaluates_to("f(1)", "undef"); + assert_parsed_expression_evaluates_to("a", "undef"); + assert_parsed_expression_evaluates_to("b", "undef"); + + // Clean the storage for other tests + Ion::Storage::sharedStorage()->recordNamed("f.func").destroy(); + Ion::Storage::sharedStorage()->recordNamed("a.exp").destroy(); + Ion::Storage::sharedStorage()->recordNamed("b.exp").destroy(); +} diff --git a/quiz/src/runner.cpp b/quiz/src/runner.cpp index 935fa44aa..b8f0e4ba7 100644 --- a/quiz/src/runner.cpp +++ b/quiz/src/runner.cpp @@ -52,7 +52,7 @@ void ion_main(int argc, char * argv[]) { if (ExceptionRun(ecp)) { ion_main_inner(); } else { - // There has been a memeory allocation problem + // There has been a memory allocation problem #if POINCARE_TREE_LOG Poincare::TreePool::sharedPool()->log(); #endif