ocarina/tests/core/random.cpp
Anna Schumaker 6cfd0d5c51 tests: Rework much of the testing library
I move the code into a new cpp file, so it is no longer a header-only
library.  I also take the chance to add a for-each function for testing
iterators.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
2015-01-13 09:35:26 -05:00

40 lines
679 B
C++

/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/random.h>
#include <tests/test.h>
#include <sstream>
unsigned int SEED = 0;
static void do_test_rng()
{
random_seed(SEED);
for (unsigned int i = 0; i <= 10; i++) {
if (i <= SEED)
test_equal(random(SEED, i), SEED);
else
test_equal(random(SEED, i), SEED + (i % (i - SEED)));
}
}
static void test_rng(unsigned int seed)
{
std::stringstream ss;
ss << " (seed = " << seed << ")";
std::string seed_str = ss.str();
SEED = seed;
test :: run("Random Number Generator Test" + seed_str, do_test_rng);
}
int main(int argc, char **argv)
{
for (unsigned int i = 0; i < 10; i++)
test_rng(i);
return 0;
}