Added some basic tests for the AST members.

Change-Id: I9a1f297fb72a57e9b58e3951c22066134c8da9ea
This commit is contained in:
Felix Raimundo
2016-03-22 12:40:28 +01:00
parent 3c514a78e0
commit 1f9b440182
6 changed files with 46 additions and 6 deletions

View File

@@ -19,8 +19,11 @@ objs += $(addprefix poincare/src/layout/,\
exponent_layout.o\
string_layout.o)
tests += $(addprefix poincare/test/,\
addition.cpp\
fraction.cpp\
integer.cpp\
product.cpp)
product.cpp\
subtraction.cpp)
# Even though flex and bison will generate both implementation and headers at
# once, we don't declare it in the Makefile. If we did, "make -jN" with N>1 may

View File

@@ -0,0 +1,12 @@
#include <quiz.h>
#include <poincare.h>
#include <assert.h>
QUIZ_CASE(poincare_addition_approximate) {
Context context;
// Note: these have to be heap allocated.
Integer *a = new Integer(1);
Integer *b = new Integer(2);
assert(Addition(a, b).approximate(context) == 3.0f);
}

View File

@@ -0,0 +1,12 @@
#include <quiz.h>
#include <poincare.h>
#include <assert.h>
QUIZ_CASE(poincare_fraction_approximate) {
Context context;
// Note: these have to be heap allocated.
Integer *a = new Integer(1);
Integer *b = new Integer(2);
assert(Fraction(a, b).approximate(context) == 0.5f);
}

View File

@@ -37,7 +37,7 @@ QUIZ_CASE(poincare_integer_subtract) {
QUIZ_CASE(poincare_integer_multiply) {
assert(Integer(12) * Integer(34) == Integer(408));
//assert(Integer(56) * Integer(0) == Integer(0));
assert(Integer(56) * Integer(0) == Integer(0));
assert(Integer(-12) * Integer(34) == Integer(-408));
assert(Integer(-12) * Integer(-34) == Integer(408));
assert(Integer(999999) * Integer(999999) == Integer("999998000001"));

View File

@@ -2,8 +2,10 @@
#include <poincare.h>
#include <assert.h>
QUIZ_CASE(poincare_multiply_approximate) {
//Context context;
//Integer a(1), b(2);
//assert(Product(&a, &b).approximate(context) == 2);
QUIZ_CASE(poincare_procuct_approximate) {
Context context;
// Note: these have to be heap allocated.
Integer *a = new Integer(1);
Integer *b = new Integer(2);
assert(Product(a, b).approximate(context) == 2.0f);
}

View File

@@ -0,0 +1,11 @@
#include <quiz.h>
#include <poincare.h>
#include <assert.h>
QUIZ_CASE(poincare_subtraction_approximate) {
Context context;
// Note: these have to be heap allocated.
Integer *a = new Integer(1);
Integer *b = new Integer(2);
assert(Subtraction(a, b).approximate(context) == -1.0f);
}