[apps/solver] Fix the polar tests

This commit is contained in:
Romain Goyet
2020-04-14 15:16:46 -04:00
committed by Ecco
parent 240e60cb68
commit 56f3204a17
2 changed files with 21 additions and 10 deletions

View File

@@ -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) {

View File

@@ -85,16 +85,31 @@ void assert_solves_to(std::initializer_list<const char *> 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