From b2591c6f3aa9820caaee37c67122c142397efaf5 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Sat, 2 Nov 2024 17:55:03 +0100
Subject: [PATCH] Add missing tests for Array and Table

---
 tests/test_Array.cpp | 21 +++++++++++++++++++++
 tests/test_Table.cpp |  6 ++++++
 2 files changed, 27 insertions(+)

diff --git a/tests/test_Array.cpp b/tests/test_Array.cpp
index 28c018cce..fbac561b8 100644
--- a/tests/test_Array.cpp
+++ b/tests/test_Array.cpp
@@ -448,6 +448,10 @@ TEST_CASE("Array", "[utils]")
       REQUIRE(sum_before_shuffle == sum_after_shuffle);
 
       REQUIRE(sum_before_shuffle == Catch::Approx(direct_sum(array)));
+
+      ReproducibleSumManager::setReproducibleSums(false);
+      REQUIRE(sum(array) == Catch::Approx(direct_sum(array)));
+      ReproducibleSumManager::setReproducibleSums(true);
     }
 
     SECTION("reproducible float sum")
@@ -1250,6 +1254,19 @@ TEST_CASE("Array", "[utils]")
         }
       }
     }
+
+    SECTION("non reproducible double sum")
+    {
+      Array<double> array(10'000);
+
+      for (size_t i = 0; i < array.size(); ++i) {
+        array[i] = ((i < (array.size() / 10)) * 1E25 + 1E10) * ((i + 1) % 1'000) * std::sin(3 * i + 1);
+      }
+
+      ReproducibleSumManager::setReproducibleSums(false);
+      REQUIRE(sum(array) == Catch::Approx(direct_sum(array)));
+      ReproducibleSumManager::setReproducibleSums(true);
+    }
   }
 
   SECTION("checking for subArrayView")
@@ -1295,6 +1312,10 @@ TEST_CASE("Array", "[utils]")
         REQUIRE(array[i] == 2 * int_i + 1);
       }
     }
+
+    std::ostringstream os;
+    os << view;
+    REQUIRE(os.str() == "0:3 1:1 2:-1 3:-3 4:-5 5:-7");
   }
 
 #ifndef NDEBUG
diff --git a/tests/test_Table.cpp b/tests/test_Table.cpp
index 5ce90fe9c..844c7ab34 100644
--- a/tests/test_Table.cpp
+++ b/tests/test_Table.cpp
@@ -310,6 +310,12 @@ TEST_CASE("Table", "[utils]")
         }
       }
     }
+
+    std::ostringstream os;
+    os << sub_table_view;
+    REQUIRE(os.str() == R"(0| 0:5 1:8 2:11
+1| 0:2 1:-1 2:-4
+)");
   }
 
   SECTION("UnsafeRowView")
-- 
GitLab