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:
parent
c7eb82c993
commit
c7cc0dbf4c
@ -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
34
test/random.cpp
Normal 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 ();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user