[test] Use strcmpWithSystemParentheses

Now there can be two types of parentheses : '(' or
UCodePointLeftSystemParenthesis. Because we do not want to complicate
the test results, when comparing a computed serialization and a result
we do not differentiate between the two types of parentheses.
This commit is contained in:
Léa Saviot
2019-06-24 13:38:26 +02:00
committed by LeaNumworks
parent 6109903f66
commit 40c5196cee
4 changed files with 37 additions and 10 deletions

View File

@@ -77,10 +77,12 @@ void assertCalculationDisplay(const char * input, ::Calculation::Calculation::Di
quiz_assert(lastCalculation->exactAndApproximateDisplayedOutputsAreEqual(context) == sign);
}
if (exactOutput) {
quiz_assert(strcmp(lastCalculation->exactOutputText(), exactOutput) == 0);
constexpr int bufferSize = 500;
char buffer[bufferSize];
quiz_assert(strcmpWithSystemParentheses(lastCalculation->exactOutputText(), exactOutput) == 0);
}
if (approximateOutput) {
quiz_assert(strcmp(lastCalculation->approximateOutputText(), approximateOutput) == 0);
quiz_assert(strcmpWithSystemParentheses(lastCalculation->approximateOutputText(), approximateOutput) == 0);
}
store->deleteAll();
}

View File

@@ -40,16 +40,16 @@ void assert_equation_system_exact_solve_to(const char * equations[], EquationSto
}
if (type == EquationStore::Type::LinearSystem) {
for (int i = 0; i < numberOfSolutions; i++) {
quiz_assert(strcmp(equationStore.variableAtIndex(i),variables[i]) == 0);
quiz_assert(strcmpWithSystemParentheses(equationStore.variableAtIndex(i),variables[i]) == 0);
}
} else {
quiz_assert(strcmp(equationStore.variableAtIndex(0), variables[0]) == 0);
quiz_assert(strcmpWithSystemParentheses(equationStore.variableAtIndex(0), variables[0]) == 0);
}
constexpr int bufferSize = 200;
char buffer[bufferSize];
for (int i = 0; i < numberOfSolutions; i++) {
equationStore.exactSolutionLayoutAtIndex(i, true).serializeForParsing(buffer, bufferSize);
quiz_assert(strcmp(buffer, solutions[i]) == 0);
quiz_assert(strcmpWithSystemParentheses(buffer, solutions[i]) == 0);
}
equationStore.removeAll();
}

View File

@@ -41,6 +41,28 @@ bool expressions_are_equal(Poincare::Expression expected, Poincare::Expression g
return identical;
}
bool isLeftParenthesisCodePoint(CodePoint c) {
return (c == UCodePointLeftSystemParenthesis) || (c == '(');
}
bool isRightParenthesisCodePoint(CodePoint c) {
return (c == UCodePointRightSystemParenthesis) || (c == ')');
}
int strcmpWithSystemParentheses(const char * s1, const char * s2) {
quiz_assert(UTF8Decoder::CharSizeOfCodePoint(UCodePointLeftSystemParenthesis) == 1);
quiz_assert(UTF8Decoder::CharSizeOfCodePoint(UCodePointRightSystemParenthesis) == 1);
while(*s1 != 0
&& ((*s1 == *s2)
|| (isLeftParenthesisCodePoint(*s1) && isLeftParenthesisCodePoint(*s2))
|| (isRightParenthesisCodePoint(*s1) && isRightParenthesisCodePoint(*s2))))
{
s1++;
s2++;
}
return (*(unsigned char *)s1) - (*(unsigned char *)s2);
}
Expression parse_expression(const char * expression, bool canBeUnparsable) {
quiz_print(expression);
Expression result = Expression::Parse(expression);
@@ -98,13 +120,14 @@ void assert_parsed_expression_process_to(const char * expression, const char * r
print_expression(e, 0);
#endif
Expression m = process(e, globalContext, target, complexFormat, angleUnit);
char buffer[500];
m.serialize(buffer, sizeof(buffer), DecimalMode, numberOfSignifiantDigits);
constexpr int bufferSize = 500;
char buffer[bufferSize];
m.serialize(buffer, bufferSize, DecimalMode, numberOfSignifiantDigits);
#if POINCARE_TESTS_PRINT_EXPRESSIONS
cout << "---- serialize to: " << buffer << " ----" << endl;
cout << "----- compared to: " << result << " ----\n" << endl;
#endif
quiz_assert(strcmp(buffer, result) == 0);
quiz_assert(strcmpWithSystemParentheses(buffer, result) == 0);
}
template<typename T>
@@ -190,7 +213,7 @@ void assert_parsed_expression_layout_serialize_to_self(const char * expressionLa
#if POINCARE_TESTS_PRINT_EXPRESSIONS
cout << "---- serialized to: " << buffer << " ----\n" << endl;
#endif
quiz_assert(strcmp(expressionLayout, buffer) == 0);
quiz_assert(strcmpWithSystemParentheses(expressionLayout, buffer) == 0);
}
void assert_expression_layouts_as(Poincare::Expression expression, Poincare::Layout layout) {
@@ -207,7 +230,7 @@ void assert_expression_layout_serialize_to(Poincare::Layout layout, const char *
cout << "---- serialized to: " << buffer << " ----" << endl;
cout << "----- compared to: " << serialization << " ----\n" << endl;
#endif
quiz_assert(strcmp(serialization, buffer) == 0);
quiz_assert(strcmpWithSystemParentheses(serialization, buffer) == 0);
}
template void assert_parsed_expression_evaluates_to<float>(char const*, char const *, Poincare::ExpressionNode::ReductionTarget, Poincare::Preferences::AngleUnit, Poincare::Preferences::ComplexFormat, int);

View File

@@ -18,6 +18,8 @@ constexpr Poincare::Preferences::ComplexFormat Real = Poincare::Preferences::Com
constexpr Poincare::Preferences::PrintFloatMode DecimalMode = Poincare::Preferences::PrintFloatMode::Decimal;
constexpr Poincare::Preferences::PrintFloatMode ScientificMode = Poincare::Preferences::PrintFloatMode::Scientific;
int strcmpWithSystemParentheses(const char * s1, const char * s2);
bool expressions_are_equal(Poincare::Expression expected, Poincare::Expression got);
Poincare::Expression parse_expression(const char * expression, bool canBeUnparsable = false);
Poincare::Expression parse_and_simplify(const char * expression);