From 7fdfe7200dd6b452884b3dc0762034bc8d9f4f5d Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Mon, 11 Jun 2018 16:13:04 +0200
Subject: [PATCH] Added sections to TinyMatrix tests

---
 tests/test_TinyMatrix.cpp | 119 ++++++++++++++++++++++----------------
 1 file changed, 69 insertions(+), 50 deletions(-)

diff --git a/tests/test_TinyMatrix.cpp b/tests/test_TinyMatrix.cpp
index cac95d6c4..e0bc8e843 100644
--- a/tests/test_TinyMatrix.cpp
+++ b/tests/test_TinyMatrix.cpp
@@ -10,7 +10,12 @@ TEST_CASE("TinyMatrix", "[algebra]") {
   REQUIRE(((A(0,0)==1) and (A(0,1)==2) and (A(0,2)==3) and
            (A(1,0)==4) and (A(1,1)==5) and (A(1,2)==6) and
            (A(2,0)==7) and (A(2,1)==8) and (A(2,2)==9)));
-  {
+
+  TinyMatrix<3,int> B(6,5,3,
+                      8,34,6,
+                      35,6,7);
+
+  SECTION("checking for equality and difference tests") {
     const TinyMatrix<3, int> copy_A = A;
     REQUIRE(((copy_A(0,0)==1) and (copy_A(0,1)==2) and (copy_A(0,2)==3) and
              (copy_A(1,0)==4) and (copy_A(1,1)==5) and (copy_A(1,2)==6) and
@@ -21,9 +26,12 @@ TEST_CASE("TinyMatrix", "[algebra]") {
     TinyMatrix<3, int> affected_A; affected_A = A;
     REQUIRE(affected_A==A);
     REQUIRE_FALSE(affected_A!=A);
+
+    REQUIRE(A!=B);
+    REQUIRE_FALSE(A==B);
   }
 
-  {
+  SECTION("checking for scalar left product") {
     const int a = 2;
     const TinyMatrix<3, int> aA = a*A;
 
@@ -31,80 +39,91 @@ TEST_CASE("TinyMatrix", "[algebra]") {
                                     8, 10, 12,
                                     14, 16, 18));
   }
-  TinyMatrix<3, int> Z = zero;
-  REQUIRE(Z == TinyMatrix<3, int>(0,0,0,
-                                  0,0,0,
-                                  0,0,0));
-  {
+
+  SECTION("checking for null matrix management") {
+    TinyMatrix<3, int> Z = zero;
+    REQUIRE(Z == TinyMatrix<3, int>(0,0,0,
+                                    0,0,0,
+                                    0,0,0));
+
     TinyMatrix<3, int> affected_Z; affected_Z = zero;
     REQUIRE(affected_Z == Z);
   }
-  TinyMatrix<3, int> I = identity;
-  REQUIRE(I == TinyMatrix<3,int>(1,0,0,
-                                 0,1,0,
-                                 0,0,1));
 
-  {
+  SECTION("checking for identity management") {
+    TinyMatrix<3, int> I = identity;
+    REQUIRE(I == TinyMatrix<3,int>(1,0,0,
+                                   0,1,0,
+                                   0,0,1));
+
     TinyMatrix<3, int> affected_I; affected_I=identity;
     REQUIRE(affected_I==I);
   }
 
-  TinyMatrix<3,int> B(6,5,3,
-                      8,34,6,
-                      35,6,7);
-  REQUIRE(A!=B);
-  REQUIRE_FALSE(A==B);
 
-  REQUIRE(A+B == TinyMatrix<3,int>(7,7,6,
-                                   12,39,12,
-                                   42,14,16));
-  {
+  SECTION("checking for matrices sum") {
+    REQUIRE(A+B == TinyMatrix<3,int>(7,7,6,
+                                     12,39,12,
+                                     42,14,16));
+
     TinyMatrix<3, int> ApB = A;
     ApB += B;
     REQUIRE(ApB==A+B);
   }
 
-  REQUIRE(A-B == TinyMatrix<3,int>(-5, -3, 0,
-                                   -4, -29, 0,
-                                   -28, 2, 2));
-  {
+  SECTION("checking for matrices difference ") {
+    REQUIRE(A-B == TinyMatrix<3,int>(-5, -3, 0,
+                                     -4, -29, 0,
+                                     -28, 2, 2));
+
     TinyMatrix<3, int> AmB = A;
     AmB -= B;
     REQUIRE(AmB==A-B);
   }
 
-  REQUIRE(A*B == TinyMatrix<3,int>(127,91,36,
-                                   274,226,84,
-                                   421,361,132));
-
-  REQUIRE(A*TinyVector<3,int>(2,-3,5) == TinyVector<3,int>(11,23,35));
+  SECTION("checking for matrices product") {
+    REQUIRE(A*B == TinyMatrix<3,int>(127,91,36,
+                                     274,226,84,
+                                     421,361,132));
+  }
 
-  TinyVector<3,int> u(1,3,7);
-  TinyVector<3,int> v(6,2,-3);
+  SECTION("checking for matrix-vector product") {
+    REQUIRE(A*TinyVector<3,int>(2,-3,5) == TinyVector<3,int>(11,23,35));
+  }
 
-  REQUIRE(tensorProduct(u,v)==TinyMatrix<3,int>(6,2,-3,
-                                                18,6,-9,
-                                                42,14,-21));
+  SECTION("checking for tensor product") {
+    const TinyVector<3,int> u(1,3,7);
+    const TinyVector<3,int> v(6,2,-3);
 
-  REQUIRE(det(TinyMatrix<1,int>(6))==6);
-  REQUIRE(det(TinyMatrix<2,int>(3,1,
-                                -3,6))==21);
-  REQUIRE(det(B)==-1444);
+    REQUIRE(tensorProduct(u,v)==TinyMatrix<3,int>(6,2,-3,
+                                                  18,6,-9,
+                                                  42,14,-21));
+  }
 
-  REQUIRE(det(TinyMatrix<4,double> (1,2.3,7,-6.2,
-                                    3,4,9,1,
-                                    4.1,5,2,-3,
-                                    2,27,3,17.5))== Approx(6661.455).epsilon(1E-14));
+  SECTION("checking for determinant calculations") {
+    REQUIRE(det(TinyMatrix<1,int>(6))==6);
+    REQUIRE(det(TinyMatrix<2,int>(3,1,
+                                  -3,6))==21);
+    REQUIRE(det(B)==-1444);
+    REQUIRE(det(TinyMatrix<4,double> (1,2.3,7,-6.2,
+                                      3,4,9,1,
+                                      4.1,5,2,-3,
+                                      2,27,3,17.5))== Approx(6661.455).epsilon(1E-14));
+  }
 
-  REQUIRE(Catch::Detail::stringify(A) == "[(1,2,3)(4,5,6)(7,8,9)]");
-  REQUIRE(Catch::Detail::stringify(TinyMatrix<1,int>(7)) == "7");
+  SECTION("checking for matrices output") {
+    REQUIRE(Catch::Detail::stringify(A) == "[(1,2,3)(4,5,6)(7,8,9)]");
+    REQUIRE(Catch::Detail::stringify(TinyMatrix<1,int>(7)) == "7");
+  }
 
 #ifndef NDEBUG
-  REQUIRE_THROWS_AS(A(3,0), AssertError);
-  REQUIRE_THROWS_AS(A(0,3), AssertError);
+  SECTION("checking for bounds vioation") {
+    REQUIRE_THROWS_AS(A(3,0), AssertError);
+    REQUIRE_THROWS_AS(A(0,3), AssertError);
 
-  const TinyMatrix<3,int>& constA = A;
-  REQUIRE_THROWS_AS(constA(3,0), AssertError);
-  REQUIRE_THROWS_AS(constA(0,3), AssertError);
+    const TinyMatrix<3,int>& constA = A;
+    REQUIRE_THROWS_AS(constA(3,0), AssertError);
+    REQUIRE_THROWS_AS(constA(0,3), AssertError);
+  }
 #endif // NDEBUG
 }
-- 
GitLab