test that attackers do not get a building bonus

This commit is contained in:
Enno Rehling 2011-03-12 17:54:57 -08:00
parent 89b3b3161f
commit 3493c651f7
1 changed files with 38 additions and 6 deletions

View File

@ -13,7 +13,7 @@ static int add_two(building * b, unit * u) {
return 2; return 2;
} }
static void test_building_bonus(CuTest * tc) static void test_defenders_get_building_bonus(CuTest * tc)
{ {
unit *du, *au; unit *du, *au;
region *r; region *r;
@ -34,17 +34,16 @@ static void test_building_bonus(CuTest * tc)
bld->size = 10; bld->size = 10;
du = test_create_unit(test_create_faction(rc_find("human")), r); du = test_create_unit(test_create_faction(rc_find("human")), r);
du->building = bld;
au = test_create_unit(test_create_faction(rc_find("human")), r); au = test_create_unit(test_create_faction(rc_find("human")), r);
du->building = bld;
b = make_battle(r); b = make_battle(r);
ds = make_side(b, du->faction, 0, 0, 0); ds = make_side(b, du->faction, 0, 0, 0);
df = make_fighter(b, du, ds, false); df = make_fighter(b, du, ds, false);
CuAssertPtrEquals(tc, bld, df->building);
as = make_side(b, au->faction, 0, 0, 0); as = make_side(b, au->faction, 0, 0, 0);
af = make_fighter(b, au, as, true); af = make_fighter(b, au, as, true);
CuAssertPtrEquals(tc, bld, df->building);
CuAssertPtrEquals(tc, 0, af->building); CuAssertPtrEquals(tc, 0, af->building);
dt.fighter = df; dt.fighter = df;
@ -54,11 +53,44 @@ static void test_building_bonus(CuTest * tc)
diff = skilldiff(at, dt, 0); diff = skilldiff(at, dt, 0);
CuAssertIntEquals(tc, -2, diff); CuAssertIntEquals(tc, -2, diff);
diff = skilldiff(dt, at, 0);
CuAssertIntEquals(tc, 0, diff);
}
static void test_attackers_get_no_building_bonus(CuTest * tc)
{
unit *au;
region *r;
building * bld;
fighter *af;
battle *b;
side *as;
building_type * btype;
test_cleanup();
test_create_world();
r = findregion(0, 0);
btype = bt_find("castle");
btype->protection = &add_two;
bld = test_create_building(r, btype);
bld->size = 10;
au = test_create_unit(test_create_faction(rc_find("human")), r);
au->building = bld;
b = make_battle(r);
as = make_side(b, au->faction, 0, 0, 0);
af = make_fighter(b, au, as, true);
CuAssertPtrEquals(tc, 0, af->building);
} }
CuSuite *get_battle_suite(void) CuSuite *get_battle_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_building_bonus); SUITE_ADD_TEST(suite, test_defenders_get_building_bonus);
SUITE_ADD_TEST(suite, test_attackers_get_no_building_bonus);
return suite; return suite;
} }