server/src/util/rng.test.c

27 lines
553 B
C
Raw Normal View History

#include <CuTest.h>
#include <ctype.h>
#include "rng.h"
static void test_rng_round(CuTest * tc)
{
2015-01-30 22:30:11 +01:00
double f;
int i, r;
for (i = 0; i < 1000; ++i) {
f = rng_double();
r = RAND_ROUND(f);
CuAssertTrue(tc, f >= 0);
CuAssertTrue(tc, r <= (int)f + 1);
CuAssertTrue(tc, r >= (int)f);
CuAssertTrue(tc, r == (int)r);
CuAssertTrue(tc, r == RAND_ROUND(r));
}
}
CuSuite *get_rng_suite(void)
{
2015-01-30 22:30:11 +01:00
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_rng_round);
return suite;
}