From 982c35bff5316a48c5d905468062444afa1a950f Mon Sep 17 00:00:00 2001
From: Florian Zill <florian.zill@ufz.de>
Date: Mon, 18 Oct 2021 15:17:09 +0200
Subject: [PATCH] [T/ML] unittest for LiftVectorToKelvin

---
 Tests/MathLib/KelvinVector.cpp | 45 ++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/Tests/MathLib/KelvinVector.cpp b/Tests/MathLib/KelvinVector.cpp
index 6d02f6d5063..53e3a200dbb 100644
--- a/Tests/MathLib/KelvinVector.cpp
+++ b/Tests/MathLib/KelvinVector.cpp
@@ -32,6 +32,22 @@ struct MaterialLibSolidsKelvinVector6 : public ::testing::Test
     ac::gtest_reporter gtest_reporter;
 };
 
+struct MaterialLibSolidsVector2 : public ::testing::Test
+{
+    static const int size = 2;
+    ac::randomEigenMatrixGenerator<double, size, 1> VectorGenerator;
+
+    ac::gtest_reporter gtest_reporter;
+};
+
+struct MaterialLibSolidsVector3 : public ::testing::Test
+{
+    static const int size = 3;
+    ac::randomEigenMatrixGenerator<double, size, 1> VectorGenerator;
+
+    ac::gtest_reporter gtest_reporter;
+};
+
 //
 // Self-test of Kelvin to tensor and back conversion, which should be identity
 // up to numerical errors.
@@ -145,6 +161,35 @@ TEST_F(MaterialLibSolidsKelvinVector6, Inverse)
         gtest_reporter);
 }
 
+//
+// Self-test of LiftVectorToKelvin and back conversion, which should be identity
+// up to numerical errors.
+//
+
+TEST_F(MaterialLibSolidsVector2, SelfTestLiftVectorToKelvin)
+{
+    auto f = [](Eigen::Vector2d const& v)
+    {
+        return (v - reduceKelvinToVector<2>(liftVectorToKelvin<2>(v))).norm() <=
+               2 * std::numeric_limits<double>::epsilon() * v.norm();
+    };
+
+    ac::check<Eigen::Vector2d>(f, 1000, ac::make_arbitrary(VectorGenerator),
+                               gtest_reporter);
+}
+
+TEST_F(MaterialLibSolidsVector3, SelfTestLiftVectorToKelvin)
+{
+    auto f = [](Eigen::Vector3d const& v)
+    {
+        return (v - reduceKelvinToVector<3>(liftVectorToKelvin<3>(v))).norm() <=
+               2 * std::numeric_limits<double>::epsilon() * v.norm();
+    };
+
+    ac::check<Eigen::Vector3d>(f, 1000, ac::make_arbitrary(VectorGenerator),
+                               gtest_reporter);
+}
+
 //
 // Tests of deviatoric and spherical projection tensors.
 //
-- 
GitLab