forked from github/server
add tests for dice_rand term evaluation
This commit is contained in:
parent
c0304ff572
commit
e2a567e9c9
1 changed files with 18 additions and 4 deletions
|
@ -5,21 +5,35 @@
|
|||
#include <ctype.h>
|
||||
|
||||
#include "rng.h"
|
||||
#include "rand.h"
|
||||
|
||||
static void test_rng_round(CuTest * tc)
|
||||
{
|
||||
double f = rng_double();
|
||||
int r = RAND_ROUND(f);
|
||||
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 <= f + 1);
|
||||
CuAssertTrue(tc, r >= f);
|
||||
CuAssertTrue(tc, r == r);
|
||||
CuAssertTrue(tc, r == RAND_ROUND(r));
|
||||
}
|
||||
|
||||
static void test_dice_rand(CuTest* tc)
|
||||
{
|
||||
CuAssertIntEquals(tc, 9, dice_rand("3*(2+1)"));
|
||||
CuAssertIntEquals(tc, 0, dice_rand("0"));
|
||||
CuAssertIntEquals(tc, -5, dice_rand("-5"));
|
||||
CuAssertIntEquals(tc, 1, dice_rand("d1"));
|
||||
CuAssertIntEquals(tc, 2, dice_rand("2d1"));
|
||||
CuAssertIntEquals(tc, 3, dice_rand("1+2"));
|
||||
CuAssertIntEquals(tc, 6, dice_rand("3*2"));
|
||||
CuAssertIntEquals(tc, -6, dice_rand("-3*2"));
|
||||
}
|
||||
|
||||
CuSuite *get_rng_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_rng_round);
|
||||
SUITE_ADD_TEST(suite, test_dice_rand);
|
||||
return suite;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue