diff --git a/test/common/math/test_math.cc b/test/common/math/test_math.cc index 2d57336ffc37ae1f54163e5f80a43e997a2fa050..c4a93b702467c6ddd287b2f7bd73d416d16b93d9 100644 --- a/test/common/math/test_math.cc +++ b/test/common/math/test_math.cc @@ -214,4 +214,25 @@ int main() DUNE_THROW(Dune::Exception, "[linspace] Not sorted in ascending order!"); } + ////////////////////////////////////////////////////////////////// + ///// Dumux::linearRegression //////////////////////////////////// + ////////////////////////////////////////////////////////////////// + { + const auto x = Dumux::linspace(0.0, 1.0, 100); + const auto [intercept, slope] = Dumux::linearRegression(x, x); + if (std::abs(intercept) > 1e-14) + DUNE_THROW(Dune::Exception, "[linearRegreesion] Wrong intercept " << intercept << ", should be 0.0."); + if (std::abs(slope-1.0) > 1e-14) + DUNE_THROW(Dune::Exception, "[linearRegreesion] Wrong slope " << slope << ", should be 1.0."); + } + { + const auto x = Dumux::linspace(0.0, 1.0, 100); + const auto y = Dumux::linspace(1.0, 3.0, 100); + const auto [intercept, slope] = Dumux::linearRegression(x, y); + if (std::abs(intercept-1.0) > 1e-14) + DUNE_THROW(Dune::Exception, "[linearRegreesion] Wrong intercept " << intercept << ", should be 1.0."); + if (std::abs(slope-2.0) > 1e-14) + DUNE_THROW(Dune::Exception, "[linearRegreesion] Wrong slope " << slope << ", should be 2.0."); + } + }