random: add a trivial test of the default generator

This allows us to ensure some level of coverage using tools like ASan.
This commit is contained in:
Danny Robson 2018-11-28 15:24:28 +11:00
parent c7eb82c993
commit c7cc0dbf4c
2 changed files with 35 additions and 0 deletions

View File

@ -568,6 +568,7 @@ if (TESTS)
preprocessor preprocessor
quaternion quaternion
rand/buckets rand/buckets
random
range range
rational rational
region region

34
test/random.cpp Normal file
View File

@ -0,0 +1,34 @@
#include "tap.hpp"
#include "random.hpp"
#include <iostream>
///////////////////////////////////////////////////////////////////////////////
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<int> (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 ();
}