mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-24 08:10:50 +01:00
53 lines
2.2 KiB
C++
53 lines
2.2 KiB
C++
#include <quiz.h>
|
|
#include <poincare.h>
|
|
#include <ion.h>
|
|
#include <assert.h>
|
|
|
|
QUIZ_CASE(poincare_fraction_approximate) {
|
|
GlobalContext globalContext;
|
|
Expression * f = Expression::parse("1/2");
|
|
assert(f->approximate(globalContext) == 0.5f);
|
|
delete f;
|
|
}
|
|
|
|
QUIZ_CASE(poincare_fraction_evaluate) {
|
|
GlobalContext globalContext;
|
|
Expression * a = Expression::parse("1/2");
|
|
Expression * e = a->evaluate(globalContext);
|
|
assert(e->approximate(globalContext) == 0.5f);
|
|
delete a;
|
|
delete e;
|
|
|
|
char expText1[50] ={'(','3','+',Ion::Charset::SmallIota,')', '/', '(','4', '+', Ion::Charset::SmallIota, ')',0};
|
|
a = Expression::parse(expText1);
|
|
e = a->evaluate(globalContext);
|
|
assert(((Complex *)e)->a() == 13.0f/17.0f && ((Complex *)e)->b() == 1.0f/17.0f);
|
|
delete a;
|
|
delete e;
|
|
|
|
a = Expression::parse("[[1,2][3,4][5,6]]/2");
|
|
e = a->evaluate(globalContext);
|
|
assert(e->operand(0)->approximate(globalContext) == 0.5f);
|
|
assert(e->operand(1)->approximate(globalContext) == 1.0f);
|
|
assert(e->operand(2)->approximate(globalContext) == 1.5f);
|
|
assert(e->operand(3)->approximate(globalContext) == 2.0f);
|
|
assert(e->operand(4)->approximate(globalContext) == 2.5f);
|
|
assert(e->operand(5)->approximate(globalContext) == 3.0f);
|
|
delete a;
|
|
delete e;
|
|
|
|
char expText2[100] ={'[','[','1',',','2','+', Ion::Charset::SmallIota,']','[','3',',','4',']','[','5',',','6',']',']','/','(','4','+',Ion::Charset::SmallIota, ')',0};
|
|
a = Expression::parse(expText2);
|
|
e = a->evaluate(globalContext);
|
|
assert(((Complex *)e->operand(0))->a() == 4.0f/17.0f && ((Complex *)e->operand(0))->b() == -1.0f/17.0f);
|
|
assert(((Complex *)e->operand(1))->a() == 9.0f/17.0f && ((Complex *)e->operand(1))->b() == 2.0f/17.0f);
|
|
assert(((Complex *)e->operand(2))->a() == 12.0f/17.0f && ((Complex *)e->operand(2))->b() == -3.0f/17.0f);
|
|
assert(((Complex *)e->operand(3))->a() == 16.0f/17.0f && ((Complex *)e->operand(3))->b() == -4.0f/17.0f);
|
|
assert(((Complex *)e->operand(4))->a() == 20.0f/17.0f && ((Complex *)e->operand(4))->b() == -5.0f/17.0f);
|
|
assert(((Complex *)e->operand(5))->a() == 24.0f/17.0f && ((Complex *)e->operand(5))->b() == -6.0f/17.0f);
|
|
delete a;
|
|
delete e;
|
|
|
|
// TODO: test matrice fraction when implemented
|
|
}
|