Commit b1e7d9f5 authored by Lukas Riedel's avatar Lukas Riedel

Use Dune floating point comparisons for interpolator unit test

parent b2cf3f1b
......@@ -10,6 +10,7 @@
#include <iostream>
#include <dune/common/exceptions.hh>
#include <dune/common/float_cmp.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/dorie/common/interpolator.hh>
......@@ -52,6 +53,7 @@ void test_nearest_neighbor ()
offset);
// check without offset
using Dune::FloatCmp::eq; // floating-point comparison
std::vector<std::vector<double>> corners;
if constexpr (dim == 2) {
corners.resize(4);
......@@ -59,10 +61,10 @@ void test_nearest_neighbor ()
corners[1] = {1.0, 0.0};
corners[2] = {0.0, 1.0};
corners[3] = {1.0, 1.0};
assert(interp->evaluate(corners[0]) == 0.0);
assert(interp->evaluate(corners[1]) == 1.0);
assert(interp->evaluate(corners[2]) == 3.0);
assert(interp->evaluate(corners[3]) == 4.0);
assert(eq(interp->evaluate(corners[0]), 0.0));
assert(eq(interp->evaluate(corners[1]), 1.0));
assert(eq(interp->evaluate(corners[2]), 3.0));
assert(eq(interp->evaluate(corners[3]), 4.0));
}
else if (dim == 3) {
corners.resize(8);
......@@ -74,14 +76,14 @@ void test_nearest_neighbor ()
corners[5] = {1.0, 0.0, 1.0};
corners[6] = {0.0, 1.0, 1.0};
corners[7] = {1.0, 1.0, 1.0};
assert(interp->evaluate(corners[0]) == 0.0);
assert(interp->evaluate(corners[1]) == 1.0);
assert(interp->evaluate(corners[2]) == 3.0);
assert(interp->evaluate(corners[3]) == 4.0);
assert(interp->evaluate(corners[4]) == 9.0);
assert(interp->evaluate(corners[5]) == 10.0);
assert(interp->evaluate(corners[6]) == 12.0);
assert(interp->evaluate(corners[7]) == 13.0);
assert(eq(interp->evaluate(corners[0]), 0.0));
assert(eq(interp->evaluate(corners[1]), 1.0));
assert(eq(interp->evaluate(corners[2]), 3.0));
assert(eq(interp->evaluate(corners[3]), 4.0));
assert(eq(interp->evaluate(corners[4]), 9.0));
assert(eq(interp->evaluate(corners[5]), 10.0));
assert(eq(interp->evaluate(corners[6]), 12.0));
assert(eq(interp->evaluate(corners[7]), 13.0));
}
// check with offset
......@@ -99,10 +101,10 @@ void test_nearest_neighbor ()
corners[1] = {1.0, 0.0};
corners[2] = {0.0, 1.0};
corners[3] = {1.0, 1.0};
assert(interp->evaluate(corners[0]) == 4.0);
assert(interp->evaluate(corners[1]) == 5.0);
assert(interp->evaluate(corners[2]) == 7.0);
assert(interp->evaluate(corners[3]) == 8.0);
assert(eq(interp->evaluate(corners[0]), 4.0));
assert(eq(interp->evaluate(corners[1]), 5.0));
assert(eq(interp->evaluate(corners[2]), 7.0));
assert(eq(interp->evaluate(corners[3]), 8.0));
}
else if (dim == 3) {
corners.resize(8);
......@@ -114,14 +116,14 @@ void test_nearest_neighbor ()
corners[5] = {1.0, 0.0, 1.0};
corners[6] = {0.0, 1.0, 1.0};
corners[7] = {1.0, 1.0, 1.0};
assert(interp->evaluate(corners[0]) == 13.0);
assert(interp->evaluate(corners[1]) == 14.0);
assert(interp->evaluate(corners[2]) == 16.0);
assert(interp->evaluate(corners[3]) == 17.0);
assert(interp->evaluate(corners[4]) == 22.0);
assert(interp->evaluate(corners[5]) == 23.0);
assert(interp->evaluate(corners[6]) == 25.0);
assert(interp->evaluate(corners[7]) == 26.0);
assert((interp->evaluate(corners[0]), 13.0));
assert((interp->evaluate(corners[1]), 14.0));
assert((interp->evaluate(corners[2]), 16.0));
assert((interp->evaluate(corners[3]), 17.0));
assert((interp->evaluate(corners[4]), 22.0));
assert((interp->evaluate(corners[5]), 23.0));
assert((interp->evaluate(corners[6]), 25.0));
assert((interp->evaluate(corners[7]), 26.0));
}
}
......@@ -148,4 +150,4 @@ int main (int argc, char** argv)
std::cerr << "Unknown exception!" << std::endl;
return 1;
}
}
\ No newline at end of file
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment