#include #include #include #include #include #include #include #include "helper.h" using namespace Poincare; constexpr Expression::FloatDisplayMode DecimalDisplay = Expression::FloatDisplayMode::Decimal; constexpr Expression::FloatDisplayMode ScientificDisplay = Expression::FloatDisplayMode::Scientific; constexpr Expression::ComplexFormat Cartesian = Expression::ComplexFormat::Cartesian; constexpr Expression::ComplexFormat Polar = Expression::ComplexFormat::Polar; template void assert_float_prints_to(T a, const char * result, Expression::FloatDisplayMode mode = ScientificDisplay, int significantDigits = 7, int bufferSize = 250) { quiz_print(result); int tagSize = 8; unsigned char tag = 'O'; char * taggedBuffer = new char[bufferSize+2*tagSize]; memset(taggedBuffer, tag, bufferSize+2*tagSize); char * buffer = taggedBuffer + tagSize; Complex::convertFloatToText(a, buffer, bufferSize, significantDigits, mode); for (int i=0; isetComplexFormat(format); Preferences::sharedPreferences()->setDisplayMode(mode); e->writeTextInBuffer(buffer, bufferSize); translate_in_ASCII_chars(buffer); for (int i=0; i c0 = Complex::Cartesian(1.0, 2.0); assert_expression_prints_to(&c0, "1+2*I", DecimalDisplay, Cartesian); Complex c1 = Complex::Cartesian(1.0, 2.0); assert_expression_prints_to(&c1, "2.2360679774998*X^(1.1071487177941*I)", DecimalDisplay, Polar); Complex c2 = Complex::Cartesian(-1.3, 2.444); assert_expression_prints_to(&c2, "-1.3+2.444*I", DecimalDisplay, Cartesian); Complex c3 = Complex::Cartesian(-1.3, 2.444); assert_expression_prints_to(&c3, "2.7682369840749*X^(2.0596486811226*I)", DecimalDisplay, Polar); Complex c4 = Complex::Cartesian(-1.3, -2.444); assert_expression_prints_to(&c4, "-1.3-2.444*I", DecimalDisplay, Cartesian); Complex c5 = Complex::Cartesian(64078208.0, 119229408.0); assert_expression_prints_to(&c5, "64078208+119229408*I", DecimalDisplay, Cartesian); Complex c6 = Complex::Cartesian(64078208.0, 119229408.0); assert_expression_prints_to(&c6, "135357557.86997*X^(1.0776501182461*I)", DecimalDisplay, Polar); Complex c7 = Complex::Cartesian(INFINITY, 119229408.0); assert_expression_prints_to(&c7, "undef", DecimalDisplay, Polar); Complex c8 = Complex::Cartesian(0.0f, 0.0f); assert_expression_prints_to(&c8, "0", DecimalDisplay, Polar); Complex c9 = Complex::Cartesian(NAN, 0.0f); assert_expression_prints_to(&c9, "undef", DecimalDisplay, Polar); Complex c10 = Complex::Cartesian(0.0f, NAN); assert_expression_prints_to(&c10, "undef", DecimalDisplay, Polar); Complex c11 = Complex::Cartesian(NAN, NAN); assert_expression_prints_to(&c11, "undef", DecimalDisplay, Polar); }