summaryrefslogtreecommitdiffstats
path: root/tests/Euler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Euler.cpp')
-rw-r--r--tests/Euler.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/tests/Euler.cpp b/tests/Euler.cpp
index 5666cd8..0a6e28e 100644
--- a/tests/Euler.cpp
+++ b/tests/Euler.cpp
@@ -2,6 +2,7 @@
#include <cmath>
#include <cstdlib>
#include <iostream>
+#include <iomanip>
// y' = y (y == C*exp(t))
double
@@ -18,8 +19,19 @@ main()
integrator.integrate(2.0);
- std::cout << integrator.y() << std::endl
- << std::exp(2.0) << std::endl;
+ double actual = integrator.y();
+ double expected = std::exp(2.0);
- return EXIT_SUCCESS;
+ std::cout << std::setprecision(10)
+ << "Numerical: " << actual << std::endl
+ << "Expected: " << expected << std::endl;
+
+ double error = std::fabs(expected - actual)/expected;
+ if (error > 0.01) {
+ std::cerr << "Error: " << 100.0*error << "%" << std::endl;
+ return EXIT_FAILURE;
+ } else {
+ std::cout << "Error: " << 100.0*error << "%" << std::endl;
+ return EXIT_SUCCESS;
+ }
}