#include #include #include "alchemy.h" #include "unit.h" #include "item.h" #include "region.h" #include #include #include #include static void test_remove_empty_units(CuTest *tc) { unit *u; int uid; test_cleanup(); test_create_world(); u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0)); uid = u->no; remove_empty_units(); CuAssertPtrNotNull(tc, findunit(uid)); u->number = 0; remove_empty_units(); CuAssertPtrEquals(tc, 0, findunit(uid)); test_cleanup(); } static void test_remove_empty_units_in_region(CuTest *tc) { unit *u; int uid; test_cleanup(); test_create_world(); u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0)); uid = u->no; remove_empty_units_in_region(u->region); CuAssertPtrNotNull(tc, findunit(uid)); u->number = 0; remove_empty_units_in_region(u->region); CuAssertPtrEquals(tc, 0, findunit(uid)); CuAssertPtrEquals(tc, 0, u->region); CuAssertPtrEquals(tc, 0, u->faction); test_cleanup(); } static void test_scale_number(CuTest *tc) { unit *u; const struct potion_type *ptype; test_cleanup(); test_create_world(); ptype = new_potiontype(it_get_or_create(rt_get_or_create("hodor")), 1); u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0)); change_effect(u, ptype, 1); CuAssertIntEquals(tc, 1, u->number); CuAssertIntEquals(tc, 1, u->hp); CuAssertIntEquals(tc, 1, get_effect(u, ptype)); scale_number(u, 2); CuAssertIntEquals(tc, 2, u->number); CuAssertIntEquals(tc, 2, u->hp); CuAssertIntEquals(tc, 2, get_effect(u, ptype)); set_level(u, SK_ALCHEMY, 1); scale_number(u, 0); CuAssertIntEquals(tc, 0, get_level(u, SK_ALCHEMY)); test_cleanup(); } CuSuite *get_unit_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_scale_number); SUITE_ADD_TEST(suite, test_remove_empty_units); SUITE_ADD_TEST(suite, test_remove_empty_units_in_region); return suite; }