From 95783fdd2e50f442c21e5a9e668d14d4985bf2a0 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Thu, 7 Sep 2023 22:18:59 +0200
Subject: [PATCH] Replace deprecated standard library call

std::random_shuffle -> std::shuffle
---
 tests/test_Array.cpp | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/tests/test_Array.cpp b/tests/test_Array.cpp
index 7efc346e2..2651ecf43 100644
--- a/tests/test_Array.cpp
+++ b/tests/test_Array.cpp
@@ -9,6 +9,7 @@
 
 #include <deque>
 #include <list>
+#include <random>
 #include <set>
 #include <unordered_set>
 #include <valarray>
@@ -343,7 +344,7 @@ TEST_CASE("Array", "[utils]")
 
       const auto sum_before_shuffle = sum(array);
 
-      std::random_shuffle(&(array[0]), &(array[0]) + array.size());
+      std::shuffle(&(array[0]), &(array[0]) + array.size(), std::mt19937{std::random_device{}()});
 
       const auto sum_after_shuffle = sum(array);
 
@@ -362,13 +363,13 @@ TEST_CASE("Array", "[utils]")
 
       const auto sum_before_shuffle = sum(array);
 
-      std::random_shuffle(&(array[0]), &(array[0]) + array.size());
+      std::shuffle(&(array[0]), &(array[0]) + array.size(), std::mt19937{std::random_device{}()});
 
       const auto sum_after_shuffle = sum(array);
 
       REQUIRE(sum_before_shuffle == sum_after_shuffle);
 
-      REQUIRE(sum_before_shuffle == Catch::Approx(direct_sum(array)));
+      REQUIRE(sum_before_shuffle == Catch::Approx(direct_sum(array)).epsilon(1E-4));
     }
 
     SECTION("reproducible TinyVector<3,double> sum")
@@ -384,7 +385,7 @@ TEST_CASE("Array", "[utils]")
 
       const auto sum_before_shuffle = sum(array);
 
-      std::random_shuffle(&(array[0]), &(array[0]) + array.size());
+      std::shuffle(&(array[0]), &(array[0]) + array.size(), std::mt19937{std::random_device{}()});
 
       ReproducibleTinyVectorSum s0(array);
 
@@ -411,7 +412,7 @@ TEST_CASE("Array", "[utils]")
 
       const auto sum_before_shuffle = sum(array);
 
-      std::random_shuffle(&(array[0]), &(array[0]) + array.size());
+      std::shuffle(&(array[0]), &(array[0]) + array.size(), std::mt19937{std::random_device{}()});
 
       ReproducibleTinyVectorSum s0(array);
 
@@ -420,9 +421,9 @@ TEST_CASE("Array", "[utils]")
       REQUIRE(sum_before_shuffle == sum_after_shuffle);
 
       auto naive_sum = direct_sum(array);
-      REQUIRE(sum_before_shuffle[0] == Catch::Approx(naive_sum[0]));
-      REQUIRE(sum_before_shuffle[1] == Catch::Approx(naive_sum[1]));
-      REQUIRE(sum_before_shuffle[2] == Catch::Approx(naive_sum[2]));
+      REQUIRE(sum_before_shuffle[0] == Catch::Approx(naive_sum[0]).epsilon(1E-4));
+      REQUIRE(sum_before_shuffle[1] == Catch::Approx(naive_sum[1]).epsilon(1E-4));
+      REQUIRE(sum_before_shuffle[2] == Catch::Approx(naive_sum[2]).epsilon(1E-4));
     }
 
     SECTION("reproducible TinyMatrix<2, 3> sum")
@@ -441,7 +442,7 @@ TEST_CASE("Array", "[utils]")
 
       const auto sum_before_shuffle = sum(array);
 
-      std::random_shuffle(&(array[0]), &(array[0]) + array.size());
+      std::shuffle(&(array[0]), &(array[0]) + array.size(), std::mt19937{std::random_device{}()});
 
       const auto sum_after_shuffle = sum(array);
 
@@ -472,7 +473,7 @@ TEST_CASE("Array", "[utils]")
 
       const auto sum_before_shuffle = sum(array);
 
-      std::random_shuffle(&(array[0]), &(array[0]) + array.size());
+      std::shuffle(&(array[0]), &(array[0]) + array.size(), std::mt19937{std::random_device{}()});
 
       const auto sum_after_shuffle = sum(array);
 
@@ -482,7 +483,7 @@ TEST_CASE("Array", "[utils]")
       REQUIRE(sum_before_shuffle(0, 0) == Catch::Approx(naive_sum(0, 0)));
       REQUIRE(sum_before_shuffle(0, 1) == Catch::Approx(naive_sum(0, 1)));
       REQUIRE(sum_before_shuffle(0, 2) == Catch::Approx(naive_sum(0, 2)));
-      REQUIRE(sum_before_shuffle(1, 0) == Catch::Approx(naive_sum(1, 0)).epsilon(1E-4));
+      REQUIRE(sum_before_shuffle(1, 0) == Catch::Approx(naive_sum(1, 0)).epsilon(5E-4));
       REQUIRE(sum_before_shuffle(1, 1) == Catch::Approx(naive_sum(1, 1)).margin(1E-6));
       REQUIRE(sum_before_shuffle(1, 2) == Catch::Approx(naive_sum(1, 2)));
     }
-- 
GitLab