mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Add Store tests
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user