Skip to content
Snippets Groups Projects
Commit bbf643a0 authored by Timo Koch's avatar Timo Koch
Browse files

[test] Add linspace to math unit test

parent 71684091
No related branches found
No related tags found
1 merge request!2269Feature/linspace open interval
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment