mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincare] Add tests on circular variables definitions
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<typename T>
|
||||
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);
|
||||
|
||||
@@ -77,8 +77,71 @@ QUIZ_CASE(poincare_store_overwrite) {
|
||||
assert_parsed_expression_simplify_to("2>g", "2");
|
||||
assert_parsed_expression_evaluates_to<double>("g(4)", "undef");
|
||||
assert_parsed_expression_evaluates_to<double>("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<double>("a", "undef");
|
||||
assert_parsed_expression_evaluates_to<double>("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<double>("a", "undef");
|
||||
assert_parsed_expression_evaluates_to<double>("b", "undef");
|
||||
assert_parsed_expression_evaluates_to<double>("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<double>("f(1)", "undef");
|
||||
assert_parsed_expression_evaluates_to<double>("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<double>("f(1)", "undef");
|
||||
assert_parsed_expression_evaluates_to<double>("g(1)", "undef");
|
||||
assert_parsed_expression_evaluates_to<double>("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<double>("f(1)", "undef");
|
||||
assert_parsed_expression_evaluates_to<double>("a", "undef");
|
||||
assert_parsed_expression_evaluates_to<double>("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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user