From 72c8b3d1c59f33de708ac4b084a80757c84b38cd Mon Sep 17 00:00:00 2001 From: maartenkeijzer Date: Tue, 11 Oct 2005 08:15:29 +0000 Subject: [PATCH] Added simplify and differentiation tests --- eo/contrib/mathsym/GNUmakefile | 2 +- eo/contrib/mathsym/test/test_diff.cpp | 17 +++++++++++++++++ eo/contrib/mathsym/test/test_simplify.cpp | 18 ++++++++++++++++++ eo/contrib/mathsym/test/testeo.cpp | 2 +- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 eo/contrib/mathsym/test/test_diff.cpp create mode 100644 eo/contrib/mathsym/test/test_simplify.cpp diff --git a/eo/contrib/mathsym/GNUmakefile b/eo/contrib/mathsym/GNUmakefile index 7da7683d..47235658 100644 --- a/eo/contrib/mathsym/GNUmakefile +++ b/eo/contrib/mathsym/GNUmakefile @@ -39,7 +39,7 @@ libsym.a: $(OBJS) rm libsym.a; ar cq $(SYMLIB) $(OBJS) check: $(TESTPROGRAMS) - test/test_compile && test/testeo && test_simplify && echo "all tests succeeded" + test/test_compile && test/testeo && test/test_simplify && test/test_diff && echo "all tests succeeded" test/test_compile: test/test_compile.o ${SYMLIB} $(CXX) -o test/test_compile test/test_compile.o $(SYMLIB) ${LIBS} diff --git a/eo/contrib/mathsym/test/test_diff.cpp b/eo/contrib/mathsym/test/test_diff.cpp new file mode 100644 index 00000000..09dd292d --- /dev/null +++ b/eo/contrib/mathsym/test/test_diff.cpp @@ -0,0 +1,17 @@ +#include +#include +#include + +using namespace std; + +int main() { + + Sym v = SymConst(1.2); + + Sym g = exp(-sqr(v)); + + cout << g << endl; + cout << differentiate(g, v.token()) << endl; + +} + diff --git a/eo/contrib/mathsym/test/test_simplify.cpp b/eo/contrib/mathsym/test/test_simplify.cpp new file mode 100644 index 00000000..73c94c59 --- /dev/null +++ b/eo/contrib/mathsym/test/test_simplify.cpp @@ -0,0 +1,18 @@ + +#include + +using namespace std; + +int main() { + + Sym c1 = SymConst(0.4); + Sym c2 = SymConst(0.3); + Sym v1 = SymVar(0); + + Sym expr = (c1 + c2) * ( (c1 + c2) * v1); + + cout << expr << endl; + cout << simplify(expr) << endl; + +} + diff --git a/eo/contrib/mathsym/test/testeo.cpp b/eo/contrib/mathsym/test/testeo.cpp index 8693bd16..a15303cb 100644 --- a/eo/contrib/mathsym/test/testeo.cpp +++ b/eo/contrib/mathsym/test/testeo.cpp @@ -102,7 +102,7 @@ int main() { cout << "****** Evaluation **********" << endl; Dataset dataset; - dataset.load_data("problem4.dat"); + dataset.load_data("test_data.txt"); IntervalBoundsCheck check(dataset.input_minima(), dataset.input_maxima()); ErrorMeasure measure(dataset, 0.90, ErrorMeasure::mean_squared_scaled);