Beispiel #1
0
static void
dice_alloc_description_test(void)
{
    char *description = dice_alloc_description(dice_make(0, 6));
    assert(0 == strcmp("0", description));
    free_or_die(description);

    description = dice_alloc_description(dice_make(5, 1));
    assert(0 == strcmp("5", description));
    free_or_die(description);

    description = dice_alloc_description(dice_make(3, 6));
    assert(0 == strcmp("3d6", description));
    free_or_die(description);

    description = dice_alloc_description(dice_make_plus(2, 8, 1));
    assert(0 == strcmp("2d8+1", description));
    free_or_die(description);

    description = dice_alloc_description(dice_make_plus(2, 4, -1));
    assert(0 == strcmp("2d4-1", description));
    free_or_die(description);

    description = dice_alloc_description(dice_make_plus_times(1, 10, 0, 10));
    assert(0 == strcmp("1d10x10", description));
    free_or_die(description);

    description = dice_alloc_description(dice_make_plus_times(1, 4, 1, 10000));
    assert(0 == strcmp("1d4+1x10000", description));
    free_or_die(description);
}
Beispiel #2
0
static void
dice_roll_test(void)
{
    struct rnd *always_one = rnd_alloc_fake_fixed(0);
    struct rnd *always_two = rnd_alloc_fake_fixed(1);
    int score;

    score = dice_roll(dice_make(0, 1), always_one, NULL);
    assert(0 == score);

    score = dice_roll(dice_make(3, 1), always_two, NULL);
    assert(3 == score);

    score = dice_roll(dice_make_plus(1, 1, 1), always_one, NULL);
    assert(2 == score);

    score = dice_roll(dice_make_plus(5, 1, -1), always_two, NULL);
    assert(4 == score);

    score = dice_roll(dice_make_plus_times(5, 1, 0, 10), always_one, NULL);
    assert(50 == score);

    score = dice_roll(dice_make_plus(0, 4, 1), always_two, NULL);
    assert(1 == score);

    rnd_free(always_one);
    rnd_free(always_two);
}
Beispiel #3
0
static void
dice_alloc_range_description_test(void)
{
    char *description = dice_alloc_range_description(dice_make(0, 6));
    assert(0 == strcmp("0", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make_plus(0, 6, 2));
    assert(0 == strcmp("2", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make_plus_times(0, 4, 4, 10));
    assert(0 == strcmp("40", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make(3, 1));
    assert(0 == strcmp("3", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make(3, 6));
    assert(0 == strcmp("3-18", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make_plus(2, 8, 1));
    assert(0 == strcmp("3-17", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make_plus(2, 4, -1));
    assert(0 == strcmp("1-7", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make_plus_times(1, 10, 0, 10));
    assert(0 == strcmp("10-100", description));
    free_or_die(description);

    description = dice_alloc_range_description(dice_make_plus_times(1, 4, 1, 10000));
    assert(0 == strcmp("20000-50000", description));
    free_or_die(description);
}
Beispiel #4
0
struct dice
dice_make_plus(int count, int sides, int modifier)
{
    return dice_make_plus_times(count, sides, modifier, 1);
}