[poincare] Add Store tests

This commit is contained in:
Léa Saviot
2018-11-05 17:25:25 +01:00
committed by Émilie Feral
parent 7b2abfe591
commit bdbae0777e
3 changed files with 36 additions and 2 deletions

View File

@@ -59,14 +59,23 @@ void translate_in_ASCII_chars(char * expression) {
}
}
Expression parse_expression(const char * expression) {
Expression parse_expression(const char * expression, bool canBeUnparsable) {
quiz_print(expression);
char buffer[500];
strlcpy(buffer, expression, sizeof(buffer));
translate_in_special_chars(buffer);
Expression result = Expression::parse(buffer);
if (!canBeUnparsable) {
quiz_assert(!result.isUninitialized());
}
return result;
}
void assert_expression_not_parsable(const char * expression) {
Expression e = parse_expression(expression, true);
quiz_assert(e.isUninitialized());
}
void assert_parsed_expression_type(const char * expression, Poincare::ExpressionNode::Type type) {
Expression e = parse_expression(expression);
quiz_assert(e.type() == type);

View File

@@ -17,7 +17,8 @@ constexpr Poincare::Preferences::PrintFloatMode ScientificMode = Poincare::Prefe
void translate_in_special_chars(char * expression);
void translate_in_ASCII_chars(char * expression);
Poincare::Expression parse_expression(const char * expression);
Poincare::Expression parse_expression(const char * expression, bool canBeUnparsable = false);
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");

View File

@@ -58,3 +58,27 @@ QUIZ_CASE(poincare_store_user_variable) {
Ion::Storage::sharedStorage()->recordNamed("f2.func").destroy();
Ion::Storage::sharedStorage()->recordNamed("funcBoth.func").destroy();
}
QUIZ_CASE(poincare_store_that_should_fail) {
// Create a helper function
assert_parsed_expression_simplify_to("1>g(x)", "1");
// Store only works on variables or functions
assert_expression_not_parsable("2>f(2)");
assert_expression_not_parsable("3>f(g(4))");
// Clean the storage for other tests
Ion::Storage::sharedStorage()->recordNamed("g.func").destroy();
}
QUIZ_CASE(poincare_store_overwrite) {
assert_parsed_expression_simplify_to("-1>g(x)", "-1");
assert_parsed_expression_simplify_to("1+g(x)>f(x)", "1+g(?)");
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();
}