Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Unit tests for xbt::random
authorYann Duplouy <yann.duplouy@inria.fr>
Tue, 12 Nov 2019 10:30:24 +0000 (11:30 +0100)
committerYann Duplouy <yann.duplouy@inria.fr>
Tue, 12 Nov 2019 10:30:24 +0000 (11:30 +0100)
src/xbt/random_test.cpp [new file with mode: 0644]

diff --git a/src/xbt/random_test.cpp b/src/xbt/random_test.cpp
new file mode 100644 (file)
index 0000000..c93049b
--- /dev/null
@@ -0,0 +1,21 @@
+/* Copyright (c) 2019. The SimGrid Team. All rights reserved.               */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "src/include/catch.hpp"
+#include "xbt/log.h"
+#include "xbt/random.hpp"
+
+TEST_CASE("xbt::random: Random Number Generation")
+{
+  SECTION("Random")
+  {
+    simgrid::xbt::random::set_mersenne_seed(12345);
+
+    REQUIRE(simgrid::xbt::random::exponential(25) == 0.00291934351538427348);
+    REQUIRE(simgrid::xbt::random::uniform_int(1, 6) == 4);
+    REQUIRE(simgrid::xbt::random::uniform_real(0, 1) == 0.31637556043369124970);
+    REQUIRE(simgrid::xbt::random::normal(0, 2) == 1.62746784745133976635);
+  }
+}