#include #include #include #include #include #include "helper.h" using namespace Poincare; QUIZ_CASE(poincare_division_evaluate) { Complex a[1] = {Complex::Float(0.5f)}; assert_parsed_expression_evaluates_to("1/2", a); Complex b[1] = {Complex::Cartesian(13.0/17.0, 1.0/17.0)}; assert_parsed_expression_evaluates_to("(3+I)/(4+I)", b); #if MATRICES_ARE_DEFINED Complex c[6] = {Complex::Float(0.5f), Complex::Float(1.0f), Complex::Float(1.5f), Complex::Float(2.0f), Complex::Float(2.5f), Complex::Float(3.0f)}; assert_parsed_expression_evaluates_to("[[1,2][3,4][5,6]]/2", c, 3, 2); Complex d[6] = {Complex::Cartesian(4.0/17.0, -1.0/17.0), Complex::Cartesian(9.0/17.0, 2.0/17.0), Complex::Cartesian(12.0/17.0, -3.0/17.0), Complex::Cartesian(16.0/17.0, -4.0/17.0), Complex::Cartesian(20.0/17.0, -5.0/17.0), Complex::Cartesian(24.0/17.0, -6.0/17.0)}; assert_parsed_expression_evaluates_to("[[1,2+I][3,4][5,6]]/(4+I)", d, 3, 2); Complex e[4] = {Complex::Float(2.0f), Complex::Float(-1.0f), Complex::Float(1.0f), Complex::Float(0.0f)}; assert_parsed_expression_evaluates_to("[[1,2][3,4]]/[[3,4][5,6]]", e, 2, 2); Complex f[4] = {Complex::Float(-9.0), Complex::Float(6.0), Complex::Float(15.0/2.0), Complex::Float(-9.0/2.0)}; assert_parsed_expression_evaluates_to("3/[[3,4][5,6]]", f, 2, 2); // TODO: add this test when inverse of complex matrix is implemented /* Complex g[4] = {Complex::Cartesian(-9.0, -12.0), Complex::Cartesian(6.0, 8.0), Complex::Cartesian(15.0/2.0, 10.0), Complex::Cartesian(-9.0/2.0, -6.0)}; assert_parsed_expression_evaluates_to("(3+4i)/[[1,2+i][3,4][5,6]]", g, 2, 2);*/ #endif Complex h[1] = {Complex::Cartesian(.5f, -.5f)}; assert_parsed_expression_evaluates_to("1E20/(1E20+1E20I)", h); Complex i[1] = {Complex::Cartesian(.5, -.5)}; assert_parsed_expression_evaluates_to("1E155/(1E155+1E155I)", i); }