mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincre/test] Rename assert_simplify -> assert_reduce
And assert_expression_simplify -> assert_expression_reduce
This commit is contained in:
committed by
EmilieNumworks
parent
c92b3d49e9
commit
9e94304db0
@@ -70,8 +70,8 @@ QUIZ_CASE(poincare_context_user_variable_simple) {
|
||||
}
|
||||
|
||||
QUIZ_CASE(poincare_context_user_variable_2_circular_variables) {
|
||||
assert_simplify("a→b");
|
||||
assert_simplify("b→a");
|
||||
assert_reduce("a→b");
|
||||
assert_reduce("b→a");
|
||||
assert_expression_approximates_to<double>("a", Undefined::Name());
|
||||
assert_expression_approximates_to<double>("b", Undefined::Name());
|
||||
|
||||
@@ -81,9 +81,9 @@ QUIZ_CASE(poincare_context_user_variable_2_circular_variables) {
|
||||
}
|
||||
|
||||
QUIZ_CASE(poincare_context_user_variable_3_circular_variables) {
|
||||
assert_simplify("a→b");
|
||||
assert_simplify("b→c");
|
||||
assert_simplify("c→a");
|
||||
assert_reduce("a→b");
|
||||
assert_reduce("b→c");
|
||||
assert_reduce("c→a");
|
||||
assert_expression_approximates_to<double>("a", Undefined::Name());
|
||||
assert_expression_approximates_to<double>("b", Undefined::Name());
|
||||
assert_expression_approximates_to<double>("c", Undefined::Name());
|
||||
@@ -96,7 +96,7 @@ QUIZ_CASE(poincare_context_user_variable_3_circular_variables) {
|
||||
|
||||
QUIZ_CASE(poincare_context_user_variable_1_circular_function) {
|
||||
// h: x → h(x)
|
||||
assert_simplify("h(x)→h(x)");
|
||||
assert_reduce("h(x)→h(x)");
|
||||
assert_expression_approximates_to<double>("h(1)", Undefined::Name());
|
||||
|
||||
// Clean the storage for other tests
|
||||
@@ -104,9 +104,9 @@ QUIZ_CASE(poincare_context_user_variable_1_circular_function) {
|
||||
}
|
||||
|
||||
QUIZ_CASE(poincare_context_user_variable_2_circular_functions) {
|
||||
assert_simplify("1→f(x)");
|
||||
assert_simplify("f(x)→g(x)");
|
||||
assert_simplify("g(x)→f(x)");
|
||||
assert_reduce("1→f(x)");
|
||||
assert_reduce("f(x)→g(x)");
|
||||
assert_reduce("g(x)→f(x)");
|
||||
assert_expression_approximates_to<double>("f(1)", Undefined::Name());
|
||||
assert_expression_approximates_to<double>("g(1)", Undefined::Name());
|
||||
|
||||
@@ -116,10 +116,10 @@ QUIZ_CASE(poincare_context_user_variable_2_circular_functions) {
|
||||
}
|
||||
|
||||
QUIZ_CASE(poincare_context_user_variable_3_circular_functions) {
|
||||
assert_simplify("1→f(x)");
|
||||
assert_simplify("f(x)→g(x)");
|
||||
assert_simplify("g(x)→h(x)");
|
||||
assert_simplify("h(x)→f(x)");
|
||||
assert_reduce("1→f(x)");
|
||||
assert_reduce("f(x)→g(x)");
|
||||
assert_reduce("g(x)→h(x)");
|
||||
assert_reduce("h(x)→f(x)");
|
||||
assert_expression_approximates_to<double>("f(1)", Undefined::Name());
|
||||
assert_expression_approximates_to<double>("g(1)", Undefined::Name());
|
||||
assert_expression_approximates_to<double>("h(1)", Undefined::Name());
|
||||
@@ -131,9 +131,9 @@ QUIZ_CASE(poincare_context_user_variable_3_circular_functions) {
|
||||
}
|
||||
|
||||
QUIZ_CASE(poincare_context_user_variable_circular_variables_and_functions) {
|
||||
assert_simplify("a→b");
|
||||
assert_simplify("b→a");
|
||||
assert_simplify("a→f(x)");
|
||||
assert_reduce("a→b");
|
||||
assert_reduce("b→a");
|
||||
assert_reduce("a→f(x)");
|
||||
assert_expression_approximates_to<double>("f(1)", Undefined::Name());
|
||||
assert_expression_approximates_to<double>("a", Undefined::Name());
|
||||
assert_expression_approximates_to<double>("b", Undefined::Name());
|
||||
@@ -146,21 +146,21 @@ QUIZ_CASE(poincare_context_user_variable_circular_variables_and_functions) {
|
||||
|
||||
QUIZ_CASE(poincare_context_user_variable_composed_functions) {
|
||||
// f: x→x^2
|
||||
assert_simplify("x^2→f(x)");
|
||||
assert_reduce("x^2→f(x)");
|
||||
// g: x→f(x-2)
|
||||
assert_simplify("f(x-2)→g(x)");
|
||||
assert_reduce("f(x-2)→g(x)");
|
||||
assert_expression_approximates_to<double>("f(2)", "4");
|
||||
assert_expression_approximates_to<double>("g(3)", "1");
|
||||
assert_expression_approximates_to<double>("g(5)", "9");
|
||||
|
||||
// g: x→f(x-2)+f(x+1)
|
||||
assert_simplify("f(x-2)+f(x+1)→g(x)");
|
||||
assert_reduce("f(x-2)+f(x+1)→g(x)");
|
||||
// Add a sum to bypass simplification
|
||||
assert_expression_approximates_to<double>("g(3)+sum(1, n, 2, 4)", "20");
|
||||
assert_expression_approximates_to<double>("g(5)", "45");
|
||||
|
||||
// g: x→x+1
|
||||
assert_simplify("x+1→g(x)");
|
||||
assert_reduce("x+1→g(x)");
|
||||
assert_expression_approximates_to<double>("f(g(4))", "25");
|
||||
// Add a sum to bypass simplification
|
||||
assert_expression_approximates_to<double>("f(g(4))+sum(1, n, 2, 4)", "28");
|
||||
@@ -172,7 +172,7 @@ QUIZ_CASE(poincare_context_user_variable_composed_functions) {
|
||||
|
||||
QUIZ_CASE(poincare_context_user_variable_functions_approximation_with_value_for_symbol) {
|
||||
// f : x→ x^2
|
||||
assert_simplify("x^2→f(x)");
|
||||
assert_reduce("x^2→f(x)");
|
||||
// Approximate f(?-2) with ? = 5
|
||||
|
||||
constexpr int bufferSize = CodePoint::MaxCodePointCharLength + 1;
|
||||
@@ -187,7 +187,7 @@ QUIZ_CASE(poincare_context_user_variable_functions_approximation_with_value_for_
|
||||
Ion::Storage::sharedStorage()->recordNamed("f.func").destroy();
|
||||
|
||||
// f : x → √(-1)
|
||||
assert_simplify("√(-1)×√(-1)→f(x)");
|
||||
assert_reduce("√(-1)×√(-1)→f(x)");
|
||||
// Approximate f(?) with ? = 5
|
||||
// Cartesian
|
||||
assert_parsed_expression_approximates_with_value_for_symbol(Function::Builder("f", 1, Symbol::Builder(UCodePointUnknown)), x, 1.0, -1.0);
|
||||
|
||||
@@ -48,7 +48,7 @@ QUIZ_CASE(poincare_properties_is_approximate) {
|
||||
assert_expression_has_property("3.4", &context, Expression::IsApproximate);
|
||||
assert_expression_has_property("2.3+1", &context, Expression::IsApproximate);
|
||||
assert_expression_has_not_property("a", &context, Expression::IsApproximate);
|
||||
assert_simplify("42.3→a");
|
||||
assert_reduce("42.3→a");
|
||||
assert_expression_has_property("a", &context, Expression::IsApproximate);
|
||||
Ion::Storage::sharedStorage()->recordNamed("a.exp").destroy();
|
||||
}
|
||||
@@ -93,7 +93,7 @@ QUIZ_CASE(poincare_properties_is_infinity) {
|
||||
assert_expression_has_property("3.4+inf", &context, Expression::IsInfinity);
|
||||
assert_expression_has_not_property("2.3+1", &context, Expression::IsInfinity);
|
||||
assert_expression_has_not_property("a", &context, Expression::IsInfinity);
|
||||
assert_simplify("42.3+inf→a");
|
||||
assert_reduce("42.3+inf→a");
|
||||
assert_expression_has_property("a", &context, Expression::IsInfinity);
|
||||
Ion::Storage::sharedStorage()->recordNamed("a.exp").destroy();
|
||||
}
|
||||
@@ -155,7 +155,7 @@ QUIZ_CASE(poincare_properties_sign) {
|
||||
assert_reduced_expression_sign("sign(π)", Positive);
|
||||
assert_reduced_expression_sign("sign(-π)", Negative);
|
||||
assert_reduced_expression_sign("a", Unknown);
|
||||
assert_simplify("42→a");
|
||||
assert_reduce("42→a");
|
||||
assert_reduced_expression_sign("a", Positive);
|
||||
Ion::Storage::sharedStorage()->recordNamed("a.exp").destroy();
|
||||
}
|
||||
@@ -232,7 +232,7 @@ QUIZ_CASE(poincare_properties_polynomial_degree) {
|
||||
assert_reduced_expression_polynomial_degree("π×x", 1);
|
||||
assert_reduced_expression_polynomial_degree("√(-1)×x", -1, "x", Real);
|
||||
// f: x→x^2+πx+1
|
||||
assert_simplify("1+π×x+x^2→f(x)");
|
||||
assert_reduce("1+π×x+x^2→f(x)");
|
||||
assert_reduced_expression_polynomial_degree("f(x)", 2);
|
||||
Ion::Storage::sharedStorage()->recordNamed("f.func").destroy();
|
||||
}
|
||||
@@ -271,7 +271,7 @@ QUIZ_CASE(poincare_properties_characteristic_range) {
|
||||
// cos(cos(x)), degree
|
||||
assert_reduced_expression_has_characteristic_range(Cosine::Builder((Expression)Cosine::Builder(Symbol::Builder(UCodePointUnknown))), 360.0f);
|
||||
// f(x) with f : x --> cos(x), degree
|
||||
assert_simplify("cos(x)→f(x)");
|
||||
assert_reduce("cos(x)→f(x)");
|
||||
assert_reduced_expression_has_characteristic_range(Function::Builder("f",1,Symbol::Builder(UCodePointUnknown)), 360.0f);
|
||||
Ion::Storage::sharedStorage()->recordNamed("f.func").destroy();
|
||||
}
|
||||
@@ -309,7 +309,7 @@ QUIZ_CASE(poincare_properties_get_variables) {
|
||||
assert_expression_has_variables("a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+aa+bb+cc+dd+ee+ff+gg+hh+ii+jj+kk+ll+mm+nn+oo", variableBuffer6, -1);
|
||||
assert_expression_has_variables("a+b+c+d+e+f+g", variableBuffer6, -1);
|
||||
// f: x→1+πx+x^2+toto
|
||||
assert_simplify("1+π×x+x^2+toto→f(x)");
|
||||
assert_reduce("1+π×x+x^2+toto→f(x)");
|
||||
const char * variableBuffer7[] = {"tata","toto", ""};
|
||||
assert_expression_has_variables("f(tata)", variableBuffer7, 2);
|
||||
Ion::Storage::sharedStorage()->recordNamed("f.func").destroy();
|
||||
@@ -347,7 +347,7 @@ QUIZ_CASE(poincare_properties_get_polynomial_coefficients) {
|
||||
assert_reduced_expression_has_polynomial_coefficient("x^2-π×x+1", "x", coefficient3);
|
||||
|
||||
// f: x→x^2+Px+1
|
||||
assert_simplify("1+π×x+x^2→f(x)");
|
||||
assert_reduce("1+π×x+x^2→f(x)");
|
||||
const char * coefficient4[] = {"1", "π", "1", 0}; //x^2+π×x+1
|
||||
assert_reduced_expression_has_polynomial_coefficient("f(x)", "x", coefficient4);
|
||||
const char * coefficient5[] = {"0", "𝐢", 0}; //√(-1)x
|
||||
@@ -356,7 +356,7 @@ QUIZ_CASE(poincare_properties_get_polynomial_coefficients) {
|
||||
assert_reduced_expression_has_polynomial_coefficient("√(-1)x", "x", coefficient6, Real);
|
||||
|
||||
// 3 -> x
|
||||
assert_simplify("3→x");
|
||||
assert_reduce("3→x");
|
||||
const char * coefficient7[] = {"4", 0};
|
||||
assert_reduced_expression_has_polynomial_coefficient("x+1", "x", coefficient7 );
|
||||
const char * coefficient8[] = {"2", "1", 0};
|
||||
|
||||
@@ -76,13 +76,13 @@ Poincare::Expression parse_expression(const char * expression, Context * context
|
||||
return result;
|
||||
}
|
||||
|
||||
void assert_simplify(const char * expression, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat, ExpressionNode::ReductionTarget target) {
|
||||
void assert_reduce(const char * expression, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat, ExpressionNode::ReductionTarget target) {
|
||||
Shared::GlobalContext globalContext;
|
||||
Expression e = parse_expression(expression, &globalContext, false);
|
||||
assert_expression_simplify(e, angleUnit, complexFormat, target, expression);
|
||||
assert_expression_reduce(e, angleUnit, complexFormat, target, expression);
|
||||
}
|
||||
|
||||
void assert_expression_simplify(Expression e, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat, ExpressionNode::ReductionTarget target, const char * printIfFailure) {
|
||||
void assert_expression_reduce(Expression e, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat, ExpressionNode::ReductionTarget target, const char * printIfFailure) {
|
||||
Shared::GlobalContext globalContext;
|
||||
e = e.reduce(ExpressionNode::ReductionContext(&globalContext, complexFormat, angleUnit, target));
|
||||
quiz_assert_print_if_failure(!(e.isUninitialized()), printIfFailure);
|
||||
|
||||
@@ -39,9 +39,9 @@ Poincare::Expression parse_expression(const char * expression, Poincare::Context
|
||||
|
||||
// Simplification
|
||||
|
||||
void assert_simplify(const char * expression, Poincare::Preferences::AngleUnit angleUnit = Radian, Poincare::Preferences::ComplexFormat complexFormat = Cartesian, Poincare::ExpressionNode::ReductionTarget target = User);
|
||||
void assert_reduce(const char * expression, Poincare::Preferences::AngleUnit angleUnit = Radian, Poincare::Preferences::ComplexFormat complexFormat = Cartesian, Poincare::ExpressionNode::ReductionTarget target = User);
|
||||
|
||||
void assert_expression_simplify(Poincare::Expression expression, Poincare::Preferences::AngleUnit angleUnit = Radian, Poincare::Preferences::ComplexFormat complexFormat = Cartesian, Poincare::ExpressionNode::ReductionTarget target = User, const char * printIfFailure = "Error");
|
||||
void assert_expression_reduce(Poincare::Expression expression, Poincare::Preferences::AngleUnit angleUnit = Radian, Poincare::Preferences::ComplexFormat complexFormat = Cartesian, Poincare::ExpressionNode::ReductionTarget target = User, const char * printIfFailure = "Error");
|
||||
|
||||
void assert_parsed_expression_simplify_to(const char * expression, const char * simplifiedExpression, Poincare::ExpressionNode::ReductionTarget target = User, Poincare::Preferences::AngleUnit angleUnit = Radian, Poincare::Preferences::ComplexFormat complexFormat = Cartesian, Poincare::ExpressionNode::SymbolicComputation symbolicComputation = ReplaceAllDefinedSymbolsWithDefinition, Poincare::ExpressionNode::UnitConversion unitConversion = DefaultUnitConversion);
|
||||
|
||||
|
||||
@@ -898,7 +898,7 @@ QUIZ_CASE(poincare_simplification_matrix) {
|
||||
assert_parsed_expression_simplify_to("transpose(√(4))", "2");
|
||||
|
||||
// Expressions with unreduced matrix
|
||||
assert_simplify("confidence(cos(2)/25,3)→a");
|
||||
assert_reduce("confidence(cos(2)/25,3)→a");
|
||||
// Check that matrices are not permuted in multiplication
|
||||
assert_parsed_expression_simplify_to("cos(3a)*abs(transpose(a))", "cos(3×confidence(cos(2)/25,3))×abs(transpose(confidence(cos(2)/25,3)))");
|
||||
assert_parsed_expression_simplify_to("abs(transpose(a))*cos(3a)", "abs(transpose(confidence(cos(2)/25,3)))×cos(3×confidence(cos(2)/25,3))");
|
||||
@@ -1054,13 +1054,13 @@ QUIZ_CASE(poincare_simplification_unit_convert) {
|
||||
assert_parsed_expression_simplify_to("4→_km/_m", Undefined::Name());
|
||||
assert_parsed_expression_simplify_to("3×_min→_s+1-1", Undefined::Name());
|
||||
|
||||
assert_simplify("_m→a", Radian, Real);
|
||||
assert_simplify("_m→b", Radian, Real);
|
||||
assert_reduce("_m→a", Radian, Real);
|
||||
assert_reduce("_m→b", Radian, Real);
|
||||
assert_parsed_expression_simplify_to("1_km→a×b", Undefined::Name());
|
||||
|
||||
assert_simplify("2→a");
|
||||
assert_reduce("2→a");
|
||||
assert_parsed_expression_simplify_to("3_m→a×_km", Undefined::Name());
|
||||
assert_simplify("2→f(x)");
|
||||
assert_reduce("2→f(x)");
|
||||
assert_parsed_expression_simplify_to("3_m→f(2)×_km", Undefined::Name());
|
||||
|
||||
// Clean the storage for other tests
|
||||
@@ -1087,13 +1087,13 @@ QUIZ_CASE(poincare_simplification_complex_format) {
|
||||
// User defined variable
|
||||
assert_parsed_expression_simplify_to("a", "a", User, Radian, Real);
|
||||
// a = 2+i
|
||||
assert_simplify("2+𝐢→a", Radian, Real);
|
||||
assert_reduce("2+𝐢→a", Radian, Real);
|
||||
assert_parsed_expression_simplify_to("a", "unreal", User, Radian, Real);
|
||||
// Clean the storage for other tests
|
||||
Ion::Storage::sharedStorage()->recordNamed("a.exp").destroy();
|
||||
// User defined function
|
||||
// f : x → x+1
|
||||
assert_simplify("x+1+𝐢→f(x)", Radian, Real);
|
||||
assert_reduce("x+1+𝐢→f(x)", Radian, Real);
|
||||
assert_parsed_expression_simplify_to("f(3)", "unreal", User, Radian, Real);
|
||||
// Clean the storage for other tests
|
||||
Ion::Storage::sharedStorage()->recordNamed("f.func").destroy();
|
||||
@@ -1173,13 +1173,13 @@ QUIZ_CASE(poincare_simplification_complex_format) {
|
||||
// User defined variable
|
||||
assert_parsed_expression_simplify_to("a", "a", User, Radian, Cartesian);
|
||||
// a = 2+i
|
||||
assert_simplify("2+𝐢→a", Radian, Cartesian);
|
||||
assert_reduce("2+𝐢→a", Radian, Cartesian);
|
||||
assert_parsed_expression_simplify_to("a", "2+𝐢", User, Radian, Cartesian);
|
||||
// Clean the storage for other tests
|
||||
Ion::Storage::sharedStorage()->recordNamed("a.exp").destroy();
|
||||
// User defined function
|
||||
// f : x → x+1
|
||||
assert_simplify("x+1+𝐢→f(x)", Radian, Cartesian);
|
||||
assert_reduce("x+1+𝐢→f(x)", Radian, Cartesian);
|
||||
assert_parsed_expression_simplify_to("f(3)", "4+𝐢", User, Radian, Cartesian);
|
||||
// Clean the storage for other tests
|
||||
Ion::Storage::sharedStorage()->recordNamed("f.func").destroy();
|
||||
@@ -1223,13 +1223,13 @@ QUIZ_CASE(poincare_simplification_complex_format) {
|
||||
// User defined variable
|
||||
assert_parsed_expression_simplify_to("a", "a", User, Radian, Polar);
|
||||
// a = 2 + 𝐢
|
||||
assert_simplify("2+𝐢→a", Radian, Polar);
|
||||
assert_reduce("2+𝐢→a", Radian, Polar);
|
||||
assert_parsed_expression_simplify_to("a", "√(5)×ℯ^\u0012\u0012-2×atan(2)+π\u0013/2×𝐢\u0013", User, Radian, Polar);
|
||||
// Clean the storage for other tests
|
||||
Ion::Storage::sharedStorage()->recordNamed("a.exp").destroy();
|
||||
// User defined function
|
||||
// f: x → x+1
|
||||
assert_simplify("x+1+𝐢→f(x)", Radian, Polar);
|
||||
assert_reduce("x+1+𝐢→f(x)", Radian, Polar);
|
||||
assert_parsed_expression_simplify_to("f(3)", "√(17)×ℯ^\u0012\u0012-2×atan(4)+π\u0013/2×𝐢\u0013", User, Radian, Polar);
|
||||
// Clean the storage for other tests
|
||||
Ion::Storage::sharedStorage()->recordNamed("f.func").destroy();
|
||||
@@ -1295,10 +1295,10 @@ QUIZ_CASE(poincare_simplification_unit_conversion) {
|
||||
QUIZ_CASE(poincare_simplification_user_function) {
|
||||
// User defined function
|
||||
// f: x → x*1
|
||||
assert_simplify("x*3→f(x)", Radian, Polar);
|
||||
assert_reduce("x*3→f(x)", Radian, Polar);
|
||||
assert_parsed_expression_simplify_to("f(1+1)", "6", User, Radian, Polar);
|
||||
// f: x → 3
|
||||
assert_simplify("3→f(x)", Radian, Polar);
|
||||
assert_reduce("3→f(x)", Radian, Polar);
|
||||
assert_parsed_expression_simplify_to("f(1/0)", Undefined::Name(), User, Radian, Polar);
|
||||
// Clean the storage for other tests
|
||||
Ion::Storage::sharedStorage()->recordNamed("f.func").destroy();
|
||||
@@ -1315,8 +1315,8 @@ QUIZ_CASE(poincare_simplification_user_function_with_convert) {
|
||||
Function::Builder(
|
||||
"f", 1,
|
||||
Symbol::Builder('x')));
|
||||
assert_expression_simplify(e);
|
||||
assert_simplify("e^(f(0))", Radian, Polar);
|
||||
assert_expression_reduce(e);
|
||||
assert_reduce("e^(f(0))", Radian, Polar);
|
||||
Ion::Storage::sharedStorage()->recordNamed("f.func").destroy();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user