Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Unit test to check if the RNG state is written and read correctly
authorYann Duplouy <yann.duplouy@inria.fr>
Wed, 15 Apr 2020 10:15:50 +0000 (12:15 +0200)
committerYann Duplouy <yann.duplouy@inria.fr>
Wed, 15 Apr 2020 10:15:50 +0000 (12:15 +0200)
src/xbt/random_test.cpp

index a35d580..a18ec23 100644 (file)
@@ -40,4 +40,18 @@ TEST_CASE("xbt::random: Random Number Generation")
     REQUIRE_THAT(simgrid::xbt::random::uniform_real(0, 1), EpsilonApprox(distC(gen)));
     REQUIRE_THAT(simgrid::xbt::random::normal(0, 2), EpsilonApprox(distD(gen)));
   }
+
+  SECTION("XBT_RNG_std write to a file")
+  {
+    simgrid::xbt::random::set_implem_std();
+    simgrid::xbt::random::set_mersenne_seed(12345);
+
+    simgrid::xbt::random::exponential(25);
+    simgrid::xbt::random::write_mersenne_state("rdm_state_tmp.txt");
+    double resB = simgrid::xbt::random::uniform_real(10, 20);
+    double resC = simgrid::xbt::random::normal(0, 2);
+    simgrid::xbt::random::read_mersenne_state("rdm_state_tmp.txt");
+    REQUIRE_THAT(simgrid::xbt::random::uniform_real(10, 20), EpsilonApprox(resB));
+    REQUIRE_THAT(simgrid::xbt::random::normal(0, 2), EpsilonApprox(resC));
+  }
 }