From bbf643a09de42c99a7977e2d23aa8c72e61d6c2a Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Thu, 1 Oct 2020 16:04:41 +0200 Subject: [PATCH] [test] Add linspace to math unit test --- test/common/math/test_math.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/common/math/test_math.cc b/test/common/math/test_math.cc index 043034fcca..934dc7f4ec 100644 --- a/test/common/math/test_math.cc +++ b/test/common/math/test_math.cc @@ -32,6 +32,7 @@ #include <iostream> #include <utility> +#include <algorithm> #include <dune/common/float_cmp.hh> #include <dune/common/fmatrix.hh> @@ -186,6 +187,33 @@ int main() try Test::checkTableInterpolation(1.5, 2.0, table); Test::checkTableInterpolation(2.0, 3.0, table); Test::checkTableInterpolation(3.0, 3.0, table); + + ////////////////////////////////////////////////////////////////// + ///// Dumux::linspace //////////////////////////////////////////// + ////////////////////////////////////////////////////////////////// + { + const auto v = Dumux::linspace(1.0, 2.0, 100); + if (!Dune::FloatCmp::eq(v.back(), 2.0)) + DUNE_THROW(Dune::Exception, "[linspace] Last point not included!"); + if (!Dune::FloatCmp::eq(v.front(), 1.0)) + DUNE_THROW(Dune::Exception, "[linspace] First point not included!"); + if (v.size() != 100) + DUNE_THROW(Dune::Exception, "[linspace] Size incorrect!"); + if (!std::is_sorted(v.begin(), v.end())) + DUNE_THROW(Dune::Exception, "[linspace] Not sorted in ascending order!"); + } + { + const auto v = Dumux::linspace(1.0, 2.0, 100, /*endPoint=*/false); + if (!Dune::FloatCmp::eq(v.back(), 2.0-0.01)) + DUNE_THROW(Dune::Exception, "[linspace] Last point not correct!"); + if (!Dune::FloatCmp::eq(v.front(), 1.0)) + DUNE_THROW(Dune::Exception, "[linspace] First point not included!"); + if (v.size() != 100) + DUNE_THROW(Dune::Exception, "[linspace] Size incorrect!"); + if (!std::is_sorted(v.begin(), v.end())) + DUNE_THROW(Dune::Exception, "[linspace] Not sorted in ascending order!"); + } + } catch (Dune::Exception& e) { std::cerr << e << std::endl; -- GitLab