068afd6276
And convert the unit test while we're at it. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
46 lines
1.4 KiB
C
46 lines
1.4 KiB
C
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/random.h>
|
|
#include <core/string.h>
|
|
#include <tests/test.h>
|
|
|
|
|
|
static void test_rng(unsigned int seed)
|
|
{
|
|
random_seed(seed);
|
|
|
|
for (unsigned int i = 0; i <= 10; i++) {
|
|
if (i <= seed)
|
|
test_equal(random_range(seed, i), seed);
|
|
else
|
|
test_equal(random_range(seed, i), seed + (i % (i - seed)));
|
|
}
|
|
}
|
|
|
|
|
|
static void test_rng_0() { test_rng(0); }
|
|
static void test_rng_1() { test_rng(1); }
|
|
static void test_rng_2() { test_rng(2); }
|
|
static void test_rng_3() { test_rng(3); }
|
|
static void test_rng_4() { test_rng(4); }
|
|
static void test_rng_5() { test_rng(5); }
|
|
static void test_rng_6() { test_rng(6); }
|
|
static void test_rng_7() { test_rng(7); }
|
|
static void test_rng_8() { test_rng(8); }
|
|
static void test_rng_9() { test_rng(9); }
|
|
|
|
|
|
DECLARE_UNIT_TESTS(
|
|
UNIT_TEST("Random Number Generator (seed = 0)", test_rng_0),
|
|
UNIT_TEST("Random Number Generator (seed = 1)", test_rng_1),
|
|
UNIT_TEST("Random Number Generator (seed = 2)", test_rng_2),
|
|
UNIT_TEST("Random Number Generator (seed = 3)", test_rng_3),
|
|
UNIT_TEST("Random Number Generator (seed = 4)", test_rng_4),
|
|
UNIT_TEST("Random Number Generator (seed = 5)", test_rng_5),
|
|
UNIT_TEST("Random Number Generator (seed = 6)", test_rng_6),
|
|
UNIT_TEST("Random Number Generator (seed = 7)", test_rng_7),
|
|
UNIT_TEST("Random Number Generator (seed = 8)", test_rng_8),
|
|
UNIT_TEST("Random Number Generator (seed = 9)", test_rng_9),
|
|
);
|