From 894b8adfa61ac87605ffe2e3b61f7820fc324ebf Mon Sep 17 00:00:00 2001
From: Timo Koch <timo.koch@iws.uni-stuttgart.de>
Date: Thu, 15 Apr 2021 09:51:06 +0000
Subject: [PATCH] [test][math] Add small unit test for linear regression

---
 test/common/math/test_math.cc | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/test/common/math/test_math.cc b/test/common/math/test_math.cc
index 2d57336ffc..c4a93b7024 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.");
+    }
+
 }
-- 
GitLab