/* This file was generated by scramble.py. */
#line 1 "src/test.py"
#include "test.h"
#line 4
static int _passed;
static int _failed;
static Dungeon* _create_test_dungeon(void);
void assert_int(str name, int v, int expected) {
    if (v == expected) {
        _passed++;
    }
#line 8
    else {
#line 10
        _failed++;
#line 13
        print("%s%s%s: expected %d but got %d", land_color_bash("red"), name, land_color_bash("end"), expected, v);
    }
}
#line 15
void unit_tests(void) {
    _passed = 0;
    _failed = 0;
    char name [100];
    for (int i = - 2; i < 2; i += 1) {
        for (int j = - 2; j < 2; j += 1) {
            for (int d = 0; d < 6; d += 1) {
                int x = i;
                int y = j;
                dungeon_move(& x, & y, d);
                int rd = dungeon_dir(i, j, x, y);
                int rdist = dungeon_distance(i, j, x, y);
                sprintf(name, "dir %d", d);
                assert_int(name, rd, d);
                sprintf(name, "dist %d/%d to %d/%d", i, j, x, y);
                assert_int(name, rdist, 1);
            }
        }
    }
#line 32
    test_spawn();
    test_archer();
    test_mage();
#line 36
    if (_failed) {
        print("%d/%d unit tests failed", _failed, _failed + _passed);
    }
#line 37
    else {
#line 39
        print("%d/%d unit tests passed", _passed, _passed);
    }
}
#line 41
void test_spawn(void) {
    Dungeon * dungeon = _create_test_dungeon();
#line 44
    dungeon_creature_new(dungeon, game->archer, 2, 16);
#line 46
    Tile * tile = dungeon_tile(dungeon, 2, 16);
    assert_int("spawn before", tile->creature, 0);
    dungeon_step(dungeon);
    assert_int("spawn after", tile->creature, 1);
}
void test_archer(void) {
    char name [100];
    for (int d = 1; d < 5; d += 1) {
        Dungeon * dungeon = _create_test_dungeon();
        int x = 2, y = 16;
        for (int i = 0; i < d; i += 1) {
            dungeon_move(& x, & y, 5);
        }
#line 58
        dungeon_creature_new(dungeon, game->archer, 2, 16);
        dungeon_creature_new(dungeon, game->troll, x, y);
        assert_int("d3", dungeon_distance(2, 16, x, y), d);
#line 62
        dungeon_step(dungeon);
        dungeon_step(dungeon);
        Creature * a = dungeon_creature(dungeon, 1);
        sprintf(name, "archer %d", d);
        if (d == 1 || d == 2) {
            assert_int(name, a->x, 2);
            assert_int(name, a->y, 16);
            assert_int(name, a->fighting, 2);
        }
#line 69
        else {
#line 71
            assert_int(name, a->x, 3);
            assert_int(name, a->y, 15);
            assert_int(name, a->fighting, 0);
        }
    }
}
#line 75
void test_mage(void) {
    char name [100];
    for (int d = 1; d < 5; d += 1) {
        Dungeon * dungeon = _create_test_dungeon();
        int x = 2, y = 16;
        for (int i = 0; i < d; i += 1) {
            dungeon_move(& x, & y, 5);
        }
#line 82
        dungeon_creature_new(dungeon, game->mage, 2, 16);
        dungeon_creature_new(dungeon, game->troll, x, y);
        assert_int("d3", dungeon_distance(2, 16, x, y), d);
#line 86
        dungeon_step(dungeon);
        dungeon_step(dungeon);
        Creature * a = dungeon_creature(dungeon, 1);
        sprintf(name, "mage %d", d);
        if (d == 1 || d == 2 || d == 3) {
            assert_int(name, a->x, 2);
            assert_int(name, a->y, 16);
            assert_int(name, a->fighting, 2);
        }
#line 93
        else {
#line 95
            assert_int(name, a->x, 3);
            assert_int(name, a->y, 15);
            assert_int(name, a->fighting, 0);
        }
    }
}
#line 99
static Dungeon* _create_test_dungeon(void) {
    Dungeon * level = dungeon_new();
    dungeon_clear(level);
    dungeon_place(level, 2, 16, 1);
    dungeon_straight(level, 2, 16, 5, 5);
#line 105
    return level;
}
/* This file was generated by scramble.py. */
