From 4e5c18db83f46a3b68cefdd8cc1bc81ccd5d7893 Mon Sep 17 00:00:00 2001
From: Christoph Lehmann <christoph.lehmann@ufz.de>
Date: Wed, 9 Feb 2022 10:37:22 +0100
Subject: [PATCH] [T] Adapted and extended weighted point unit tests

---
 Tests/MathLib/TestWeightedPoint.cpp | 179 ++++++++++++++++++++++++----
 1 file changed, 153 insertions(+), 26 deletions(-)

diff --git a/Tests/MathLib/TestWeightedPoint.cpp b/Tests/MathLib/TestWeightedPoint.cpp
index f92ab3a18ce..89498c6f286 100644
--- a/Tests/MathLib/TestWeightedPoint.cpp
+++ b/Tests/MathLib/TestWeightedPoint.cpp
@@ -9,43 +9,170 @@
 
 #include <gtest/gtest.h>
 
-#include "MathLib/TemplateWeightedPoint.h"
+#include "MathLib/WeightedPoint.h"
+
+TEST(MathLib, WeightedPoint0D)
+{
+    std::array<double, 0> const pnt{};
+    double const w = 50.0;
+    MathLib::WeightedPoint const wpnt_0d(pnt, w);
+
+    ASSERT_EQ(0, wpnt_0d.getDimension());
+    ASSERT_EQ(w, wpnt_0d.getWeight());
+}
 
 TEST(MathLib, WeightedPoint1D)
 {
-    std::array<double, 1> pnt;
-    pnt[0] = 0.5;
-    double w = 100.0;
-    MathLib::WeightedPoint1D wpnt_1d(pnt, w);
+    std::array<double, 1> pnt{0.5};
+    double const w = 100.0;
+    MathLib::WeightedPoint const wpnt_1d(pnt, w);
 
-    ASSERT_NEAR(pnt[0], wpnt_1d[0], std::numeric_limits<double>::epsilon());
-    ASSERT_NEAR(w, wpnt_1d.getWeight(), std::numeric_limits<double>::epsilon());
+    ASSERT_EQ(1, wpnt_1d.getDimension());
+    ASSERT_EQ(pnt[0], wpnt_1d[0]);
+    ASSERT_EQ(w, wpnt_1d.getWeight());
 }
 
 TEST(MathLib, WeightedPoint2D)
 {
-    std::array<double, 2> pnt;
-    pnt[0] = 0.1;
-    pnt[1] = 0.2;
-    double w = 200.0;
-    MathLib::WeightedPoint2D wpnt_2d(pnt, w);
+    std::array<double, 2> const pnt{0.1, 0.2};
+    double const w = 200.0;
+    MathLib::WeightedPoint const wpnt_2d(pnt, w);
 
-    ASSERT_NEAR(pnt[0], wpnt_2d[0], std::numeric_limits<double>::epsilon());
-    ASSERT_NEAR(pnt[1], wpnt_2d[1], std::numeric_limits<double>::epsilon());
-    ASSERT_NEAR(w, wpnt_2d.getWeight(), std::numeric_limits<double>::epsilon());
+    ASSERT_EQ(2, wpnt_2d.getDimension());
+    ASSERT_EQ(pnt[0], wpnt_2d[0]);
+    ASSERT_EQ(pnt[1], wpnt_2d[1]);
+    ASSERT_EQ(w, wpnt_2d.getWeight());
 }
 
 TEST(MathLib, WeightedPoint3D)
 {
-    std::array<double, 3> pnt;
-    pnt[0] = 0.1;
-    pnt[1] = 0.2;
-    pnt[2] = 0.3;
-    double w = 300.0;
-    MathLib::WeightedPoint3D wpnt_3d(pnt, w);
-
-    ASSERT_NEAR(pnt[0], wpnt_3d[0], std::numeric_limits<double>::epsilon());
-    ASSERT_NEAR(pnt[1], wpnt_3d[1], std::numeric_limits<double>::epsilon());
-    ASSERT_NEAR(pnt[2], wpnt_3d[2], std::numeric_limits<double>::epsilon());
-    ASSERT_NEAR(w, wpnt_3d.getWeight(), std::numeric_limits<double>::epsilon());
+    std::array<double, 3> const pnt{0.1, 0.2, 0.3};
+    double const w = 300.0;
+    MathLib::WeightedPoint const wpnt_3d(pnt, w);
+
+    ASSERT_EQ(3, wpnt_3d.getDimension());
+    ASSERT_EQ(pnt[0], wpnt_3d[0]);
+    ASSERT_EQ(pnt[1], wpnt_3d[1]);
+    ASSERT_EQ(pnt[2], wpnt_3d[2]);
+    ASSERT_EQ(w, wpnt_3d.getWeight());
+}
+
+TEST(MathLib, WeightedPointEquality3D)
+{
+    MathLib::WeightedPoint const orig{std::array{0.1, 0.2, 0.3}, 0.4};
+
+    {
+        MathLib::WeightedPoint const same{std::array{0.1, 0.2, 0.3}, 0.4};
+        ASSERT_EQ(orig, same);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_x{std::array{0.15, 0.2, 0.3}, 0.4};
+        ASSERT_NE(orig, diff_x);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_y{std::array{0.1, 0.25, 0.3}, 0.4};
+        ASSERT_NE(orig, diff_y);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_z{std::array{0.1, 0.2, 0.35}, 0.4};
+        ASSERT_NE(orig, diff_z);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_w{std::array{0.1, 0.2, 0.3}, 0.45};
+        ASSERT_NE(orig, diff_w);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_dim0{std::array<double, 0>{}, 0.4};
+        ASSERT_NE(orig, diff_dim0);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_dim1{std::array{0.1}, 0.4};
+        ASSERT_NE(orig, diff_dim1);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_dim2{std::array{0.1, 0.2}, 0.4};
+        ASSERT_NE(orig, diff_dim2);
+    }
+}
+
+TEST(MathLib, WeightedPointEquality2D)
+{
+    MathLib::WeightedPoint const orig{std::array{0.1, 0.2}, 0.4};
+
+    {
+        MathLib::WeightedPoint const same{std::array{0.1, 0.2}, 0.4};
+        ASSERT_EQ(orig, same);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_x{std::array{0.15, 0.2}, 0.4};
+        ASSERT_NE(orig, diff_x);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_y{std::array{0.1, 0.25}, 0.4};
+        ASSERT_NE(orig, diff_y);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_w{std::array{0.1, 0.2}, 0.45};
+        ASSERT_NE(orig, diff_w);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_dim0{std::array<double, 0>{}, 0.4};
+        ASSERT_NE(orig, diff_dim0);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_dim1{std::array{0.1}, 0.4};
+        ASSERT_NE(orig, diff_dim1);
+    }
+}
+
+TEST(MathLib, WeightedPointEquality1D)
+{
+    MathLib::WeightedPoint const orig{std::array{0.1}, 0.4};
+
+    {
+        MathLib::WeightedPoint const same{std::array{0.1}, 0.4};
+        ASSERT_EQ(orig, same);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_x{std::array{0.15}, 0.4};
+        ASSERT_NE(orig, diff_x);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_w{std::array{0.1}, 0.45};
+        ASSERT_NE(orig, diff_w);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_dim0{std::array<double, 0>{}, 0.4};
+        ASSERT_NE(orig, diff_dim0);
+    }
+}
+
+TEST(MathLib, WeightedPointEquality0D)
+{
+    MathLib::WeightedPoint const orig{0.4};
+
+    {
+        MathLib::WeightedPoint const same{0.4};
+        ASSERT_EQ(orig, same);
+    }
+
+    {
+        MathLib::WeightedPoint const diff_w{0.45};
+        ASSERT_NE(orig, diff_w);
+    }
 }
-- 
GitLab