From 61aa4439a0ba37e5b39e34c91b162bcedb413818 Mon Sep 17 00:00:00 2001 From: Yann Duplouy Date: Tue, 12 Nov 2019 11:30:24 +0100 Subject: [PATCH] Unit tests for xbt::random --- src/xbt/random_test.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/xbt/random_test.cpp diff --git a/src/xbt/random_test.cpp b/src/xbt/random_test.cpp new file mode 100644 index 0000000000..c93049b8b0 --- /dev/null +++ b/src/xbt/random_test.cpp @@ -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); + } +} -- 2.20.1