#include #include #include #include #include #include #include using namespace Poincare; static Expression * parse_expression(const char * expression) { quiz_print(expression); char buffer[200]; strlcpy(buffer, expression, sizeof(buffer)); for (char *c = buffer; *c; c++) { switch (*c) { case 'E': *c = Ion::Charset::Exponent; break; case 'X': *c = Ion::Charset::Exponential; break; case 'I': *c = Ion::Charset::IComplex; break; case 'R': *c = Ion::Charset::Root; break; case 'P': *c = Ion::Charset::SmallPi; break; } } Expression * result = Expression::parse(buffer); assert(result); return result; } void assert_parsed_expression_type(const char * expression, Poincare::Expression::Type type) { Expression * e = parse_expression(expression); assert(e->type() == type); delete e; } #if POINCARE_SIMPLIFY void assert_parsed_simplified_expression_type(const char * expression, Poincare::Expression::Type type) { Expression * e = parse_expression(expression); Expression * e2 = e->simplify(); assert(e2); assert(e2->type() == type); delete e; delete e2; } #endif template void assert_parsed_expression_evaluates_to(const char * expression, Complex * results, int numberOfRows, int numberOfColumns, Expression::AngleUnit angleUnit) { GlobalContext globalContext; Expression * a = parse_expression(expression); Evaluation * m = a->evaluate(globalContext, angleUnit); assert(m); assert(m->numberOfRows() == numberOfRows); assert(m->numberOfColumns() == numberOfColumns); for (int i = 0; i < m->numberOfOperands(); i++) { assert(std::fabs(m->complexOperand(i)->a() - results[i].a()) < 0.0001f); assert(std::fabs(m->complexOperand(i)->b() - results[i].b()) < 0.0001f); } delete a; delete m; } template void assert_parsed_expression_evaluates_to(char const*, Poincare::Complex*, int, int, Poincare::Expression::AngleUnit); template void assert_parsed_expression_evaluates_to(char const*, Poincare::Complex*, int, int, Poincare::Expression::AngleUnit);