summaryrefslogtreecommitdiffstats
path: root/tests/Midpoint.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Midpoint.cpp')
-rw-r--r--tests/Midpoint.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/tests/Midpoint.cpp b/tests/Midpoint.cpp
index aea1885..9be7bb7 100644
--- a/tests/Midpoint.cpp
+++ b/tests/Midpoint.cpp
@@ -2,6 +2,7 @@
#include <cmath>
#include <cstdlib>
#include <iostream>
+#include <iomanip>
// y' = y (y == C*exp(t))
double
@@ -14,12 +15,23 @@ int
main()
{
vZ::MidpointIntegrator integrator(f);
- integrator.y(1.0).x(0.0).h(0.02);
+ integrator.y(1.0).x(0.0).h(0.01);
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 > 3.4e-5) {
+ std::cerr << "Error: " << 100.0*error << "%" << std::endl;
+ return EXIT_FAILURE;
+ } else {
+ std::cout << "Error: " << 100.0*error << "%" << std::endl;
+ return EXIT_SUCCESS;
+ }
}