mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-24 00:00:44 +01:00
Merge changes Iea9c7cb8,If8d97134
* changes: [poincare] Parse ".004" [poincare] Add tests for the parser
This commit is contained in:
@@ -63,6 +63,7 @@ tests += $(addprefix poincare/test/,\
|
||||
identity.cpp\
|
||||
integer.cpp\
|
||||
matrix.cpp\
|
||||
parser.cpp\
|
||||
product.cpp\
|
||||
power.cpp\
|
||||
simplify_utils.cpp\
|
||||
|
||||
@@ -112,8 +112,11 @@ mtxData:
|
||||
|
||||
number:
|
||||
DIGITS { $$ = new Integer($1.address, false); }
|
||||
| DOT DIGITS { $$ = new Complex(nullptr, 0, false, $2.address, $2.length, nullptr, 0, false); }
|
||||
| DIGITS DOT DIGITS { $$ = new Complex($1.address, $1.length, false, $3.address, $3.length, nullptr, 0, false); }
|
||||
| DOT DIGITS EE DIGITS { $$ = new Complex(nullptr, 0, false, $2.address, $2.length, $4.address, $4.length, false); }
|
||||
| DIGITS DOT DIGITS EE DIGITS { $$ = new Complex($1.address, $1.length, false, $3.address, $3.length, $5.address, $5.length, false); }
|
||||
| DOT DIGITS EE MINUS DIGITS { $$ = new Complex(nullptr, 0, false, $2.address, $2.length, $5.address, $5.length, true); }
|
||||
| DIGITS DOT DIGITS EE MINUS DIGITS { $$ = new Complex($1.address, $1.length, false, $3.address, $3.length, $6.address, $6.length, true); }
|
||||
|
||||
exp:
|
||||
|
||||
36
poincare/test/parser.cpp
Normal file
36
poincare/test/parser.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <quiz.h>
|
||||
#include <poincare.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
QUIZ_CASE(poincare_parser) {
|
||||
GlobalContext globalContext;
|
||||
Expression * a = Expression::parse("1.2*e^(1)");
|
||||
float f =1.2f*M_E;
|
||||
assert(a->approximate(globalContext) == f);
|
||||
|
||||
a = Expression::parse("e^2*e^(1)");
|
||||
f = powf(M_E, 2.0f)*M_E;
|
||||
assert(a->approximate(globalContext) == f);
|
||||
|
||||
a = Expression::parse("2*3^4+2");
|
||||
f = 2.0f*powf(3.0f, 4.0f)+2.0f;
|
||||
assert(a->approximate(globalContext) == f);
|
||||
|
||||
a = Expression::parse("-2*3^4+2");
|
||||
f = -2.0f*powf(3.0f, 4.0f)+2.0f;
|
||||
assert(a->approximate(globalContext) == f);
|
||||
|
||||
a = Expression::parse("-sin(3)*2-3");
|
||||
f = -sinf(3.0f)*2.0f-3.0f;
|
||||
assert(a->approximate(globalContext) == f);
|
||||
|
||||
a = Expression::parse("-.003");
|
||||
f = -0.003f;
|
||||
assert(a->approximate(globalContext) == f);
|
||||
|
||||
char text[10] = {'.', '0', '2', 'E', '2', 0};
|
||||
a = Expression::parse(text);
|
||||
f = 2.0f;
|
||||
assert(a->approximate(globalContext) == f);
|
||||
}
|
||||
Reference in New Issue
Block a user