Commit 894b8adf authored by Timo Koch's avatar Timo Koch
Browse files

[test][math] Add small unit test for linear regression

parent 31c5e810
......@@ -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.");
}
}
Supports Markdown
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