diff --git a/apps/solver/test/equation_store.cpp b/apps/solver/test/equation_store.cpp index ba16a599d..dae5ab888 100644 --- a/apps/solver/test/equation_store.cpp +++ b/apps/solver/test/equation_store.cpp @@ -114,17 +114,13 @@ QUIZ_CASE(equation_solve_complex_cartesian) { } QUIZ_CASE(equation_solve_complex_polar) { - // TODO: Does it make sense to test polar vs cartesian? - // It doesn't seem to work when converting expressions anyway... -#if 0 set_complex_format(Polar); assert_solves_to("x+𝐢=0", "x=ℯ^(-(π/2)𝐢)"); assert_solves_to("x+√(-1)=0", "x=ℯ^(-(π/2)𝐢)"); - assert_quadratic_solves_to("x^2+x+1=0", {"x=ℯ^(-(2π/3)𝐢)", "x=ℯ^((2π/3)𝐢)"}); - assert_quadratic_solves_to("x^2-√(-1)=0", {"x=ℯ^(-(3×π/4)𝐢)", "x=ℯ^((π/4)𝐢)"}); - assert_solves_to("root(-8,3)*x+3=0", "x=3/2ℯ^((2π/3)𝐢)"); + assert_solves_to("x^2+x+1=0", {"x=ℯ^(-(2π/3)𝐢)", "x=ℯ^((2π/3)𝐢)", "delta=3ℯ^(𝐢π)"}); + assert_solves_to("x^2-√(-1)=0", {"x=ℯ^(-(3×π/4)𝐢)", "x=ℯ^((π/4)𝐢)", "delta=4ℯ^(𝐢π/2)"}); + assert_solves_to("root(-8,3)*x+3=0", "x=3/2×ℯ^((2π/3)𝐢)"); reset_complex_format(); -#endif } QUIZ_CASE(equation_and_symbolic_computation) { diff --git a/apps/solver/test/helpers.cpp b/apps/solver/test/helpers.cpp index 1c4561fb0..ed0f1c184 100644 --- a/apps/solver/test/helpers.cpp +++ b/apps/solver/test/helpers.cpp @@ -85,16 +85,31 @@ void assert_solves_to(std::initializer_list equations, std::initia const char * expectedValue = equal + 1; Preferences::ComplexFormat complexFormat = Preferences::sharedPreferences()->complexFormat(); + + /* We want to give complex results to equations that explicitely use 𝐢 + * As a result, we need to enforce a non-real complex format here. */ if (complexFormat == Preferences::ComplexFormat::Real) { complexFormat = Preferences::ComplexFormat::Cartesian; } - Expression expectedExpression = Expression::ParseAndSimplify( - expectedValue, + /* We're pretty much reinventing ParseAndSimplify here. + * But for some reason, we really need to call simplifyAndApproximate, + * otherwise simplification of Polar numbers don't work. For instance, + * ParseAndSimplify("𝐢") will yield "𝐢", even in Polar mode! + * We're using the same weird trick as in assert_parsed_expression_simplify_to + * TODO: Fix ParseAndSimplify */ + + Expression expectedExpression = Expression::Parse(expectedValue, &globalContext, false); + quiz_assert(!expectedExpression.isUninitialized()); + expectedExpression.simplifyAndApproximate( + &expectedExpression, + nullptr, &globalContext, complexFormat, - Preferences::sharedPreferences()->angleUnit() + Preferences::sharedPreferences()->angleUnit(), + ExpressionNode::SymbolicComputation::ReplaceAllDefinedSymbolsWithDefinition ); + Layout expectedLayout = expectedExpression.createLayout(Preferences::PrintFloatMode::Decimal, 5); Layout obtainedLayout = store->exactSolutionLayoutAtIndex(i, true); #if 0