From c7cc0dbf4cb7c58da7c0f371670caa7b649451b0 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 28 Nov 2018 15:24:28 +1100 Subject: [PATCH] random: add a trivial test of the default generator This allows us to ensure some level of coverage using tools like ASan. --- CMakeLists.txt | 1 + test/random.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/random.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a6600f9e..cdfa1058 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -568,6 +568,7 @@ if (TESTS) preprocessor quaternion rand/buckets + random range rational region diff --git a/test/random.cpp b/test/random.cpp new file mode 100644 index 00000000..a8c17195 --- /dev/null +++ b/test/random.cpp @@ -0,0 +1,34 @@ +#include "tap.hpp" + +#include "random.hpp" + +#include + + +/////////////////////////////////////////////////////////////////////////////// +int +main () +{ + cruft::TAP::logger tap; + + { + constexpr int ITERATIONS = 2048; + constexpr int HI = 13; + constexpr int LO = 3; + + bool success = true; + + for (int i = 0; i < ITERATIONS; ++i) { + auto const val = cruft::random::uniform (LO, HI); + if (val < LO || val > HI) { + std::cerr << val << '\n'; + success = false; + break; + } + } + + tap.expect (success, "default uniform random int is within correct range"); + } + + return tap.status (); +} \ No newline at end of file