forked from github/server
basic test for skilldiff.
This commit is contained in:
parent
194f96c50f
commit
23a91be9c1
|
@ -203,10 +203,14 @@ static void test_building_defence_bonus(CuTest * tc)
|
||||||
}
|
}
|
||||||
|
|
||||||
static fighter *setup_fighter(battle **bp, unit *u) {
|
static fighter *setup_fighter(battle **bp, unit *u) {
|
||||||
battle *b;
|
battle *b = *bp;
|
||||||
|
side *s;
|
||||||
|
|
||||||
|
if (!b) {
|
||||||
*bp = b = make_battle(u->region);
|
*bp = b = make_battle(u->region);
|
||||||
return make_fighter(b, u, make_side(b, u->faction, 0, 0, 0), false);
|
}
|
||||||
|
s = make_side(b, u->faction, 0, 0, 0);
|
||||||
|
return make_fighter(b, u, s, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_natural_armor(CuTest * tc)
|
static void test_natural_armor(CuTest * tc)
|
||||||
|
@ -229,7 +233,7 @@ static void test_natural_armor(CuTest * tc)
|
||||||
static void test_calculate_armor(CuTest * tc)
|
static void test_calculate_armor(CuTest * tc)
|
||||||
{
|
{
|
||||||
troop dt;
|
troop dt;
|
||||||
battle *b;
|
battle *b = NULL;
|
||||||
region *r;
|
region *r;
|
||||||
unit *du;
|
unit *du;
|
||||||
weapon_type *wtype;
|
weapon_type *wtype;
|
||||||
|
@ -255,6 +259,7 @@ static void test_calculate_armor(CuTest * tc)
|
||||||
CuAssertDblEquals_Msg(tc, "magres unmodified", 1.0, magres, 0.01);
|
CuAssertDblEquals_Msg(tc, "magres unmodified", 1.0, magres, 0.01);
|
||||||
free_battle(b);
|
free_battle(b);
|
||||||
|
|
||||||
|
b = NULL;
|
||||||
i_change(&du->items, ibelt, 1);
|
i_change(&du->items, ibelt, 1);
|
||||||
dt.fighter = setup_fighter(&b, du);
|
dt.fighter = setup_fighter(&b, du);
|
||||||
CuAssertIntEquals_Msg(tc, "magical armor", 1, calculate_armor(dt, 0, 0, 0));
|
CuAssertIntEquals_Msg(tc, "magical armor", 1, calculate_armor(dt, 0, 0, 0));
|
||||||
|
@ -263,6 +268,7 @@ static void test_calculate_armor(CuTest * tc)
|
||||||
rc->armor = 0;
|
rc->armor = 0;
|
||||||
free_battle(b);
|
free_battle(b);
|
||||||
|
|
||||||
|
b = NULL;
|
||||||
i_change(&du->items, ishield, 1);
|
i_change(&du->items, ishield, 1);
|
||||||
i_change(&du->items, ichain, 1);
|
i_change(&du->items, ichain, 1);
|
||||||
dt.fighter = setup_fighter(&b, du);
|
dt.fighter = setup_fighter(&b, du);
|
||||||
|
@ -270,6 +276,7 @@ static void test_calculate_armor(CuTest * tc)
|
||||||
CuAssertIntEquals_Msg(tc, "require BF_EQUIPMENT", 1, calculate_armor(dt, 0, 0, 0));
|
CuAssertIntEquals_Msg(tc, "require BF_EQUIPMENT", 1, calculate_armor(dt, 0, 0, 0));
|
||||||
free_battle(b);
|
free_battle(b);
|
||||||
|
|
||||||
|
b = NULL;
|
||||||
rc->battle_flags |= BF_EQUIPMENT;
|
rc->battle_flags |= BF_EQUIPMENT;
|
||||||
dt.fighter = setup_fighter(&b, du);
|
dt.fighter = setup_fighter(&b, du);
|
||||||
CuAssertIntEquals_Msg(tc, "stack equipment rc", 5, calculate_armor(dt, 0, 0, 0));
|
CuAssertIntEquals_Msg(tc, "stack equipment rc", 5, calculate_armor(dt, 0, 0, 0));
|
||||||
|
@ -296,7 +303,7 @@ static void test_calculate_armor(CuTest * tc)
|
||||||
static void test_magic_resistance(CuTest *tc)
|
static void test_magic_resistance(CuTest *tc)
|
||||||
{
|
{
|
||||||
troop dt;
|
troop dt;
|
||||||
battle *b;
|
battle *b = NULL;
|
||||||
region *r;
|
region *r;
|
||||||
unit *du;
|
unit *du;
|
||||||
armor_type *ashield, *achain;
|
armor_type *ashield, *achain;
|
||||||
|
@ -324,6 +331,7 @@ static void test_magic_resistance(CuTest *tc)
|
||||||
calculate_armor(dt, 0, 0, &magres);
|
calculate_armor(dt, 0, 0, &magres);
|
||||||
free_battle(b);
|
free_battle(b);
|
||||||
|
|
||||||
|
b = NULL;
|
||||||
i_change(&du->items, ishield, 1);
|
i_change(&du->items, ishield, 1);
|
||||||
i_change(&du->items, ichain, 1);
|
i_change(&du->items, ichain, 1);
|
||||||
achain->flags |= ATF_LAEN;
|
achain->flags |= ATF_LAEN;
|
||||||
|
@ -335,6 +343,7 @@ static void test_magic_resistance(CuTest *tc)
|
||||||
CuAssertDblEquals_Msg(tc, "laen reduction", 0.81, magres, 0.01);
|
CuAssertDblEquals_Msg(tc, "laen reduction", 0.81, magres, 0.01);
|
||||||
free_battle(b);
|
free_battle(b);
|
||||||
|
|
||||||
|
b = NULL;
|
||||||
i_change(&du->items, ishield, -1);
|
i_change(&du->items, ishield, -1);
|
||||||
i_change(&du->items, ichain, -1);
|
i_change(&du->items, ichain, -1);
|
||||||
set_level(du, SK_MAGIC, 2);
|
set_level(du, SK_MAGIC, 2);
|
||||||
|
@ -359,7 +368,7 @@ static void test_magic_resistance(CuTest *tc)
|
||||||
static void test_projectile_armor(CuTest * tc)
|
static void test_projectile_armor(CuTest * tc)
|
||||||
{
|
{
|
||||||
troop dt;
|
troop dt;
|
||||||
battle *b;
|
battle *b = NULL;
|
||||||
region *r;
|
region *r;
|
||||||
unit *du;
|
unit *du;
|
||||||
weapon_type *wtype;
|
weapon_type *wtype;
|
||||||
|
@ -394,10 +403,37 @@ static void test_projectile_armor(CuTest * tc)
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_battle_skilldiff(CuTest *tc)
|
||||||
|
{
|
||||||
|
troop ta, td;
|
||||||
|
region *r;
|
||||||
|
unit *ua, *ud;
|
||||||
|
battle *b = NULL;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
r = test_create_region(0, 0, 0);
|
||||||
|
ud = test_create_unit(test_create_faction(0), r);
|
||||||
|
ua = test_create_unit(test_create_faction(0), r);
|
||||||
|
td.fighter = setup_fighter(&b, ud);
|
||||||
|
td.index = 0;
|
||||||
|
ta.fighter = setup_fighter(&b, ua);
|
||||||
|
ta.index = 0;
|
||||||
|
ua = test_create_unit(test_create_faction(0), r);
|
||||||
|
CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0));
|
||||||
|
|
||||||
|
ta.fighter->person[0].attack = 2;
|
||||||
|
td.fighter->person[0].defence = 1;
|
||||||
|
CuAssertIntEquals(tc, 1, skilldiff(ta, td, 0));
|
||||||
|
|
||||||
|
free_battle(b);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_battle_suite(void)
|
CuSuite *get_battle_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_make_fighter);
|
SUITE_ADD_TEST(suite, test_make_fighter);
|
||||||
|
SUITE_ADD_TEST(suite, test_battle_skilldiff);
|
||||||
SUITE_ADD_TEST(suite, test_defenders_get_building_bonus);
|
SUITE_ADD_TEST(suite, test_defenders_get_building_bonus);
|
||||||
SUITE_ADD_TEST(suite, test_attackers_get_no_building_bonus);
|
SUITE_ADD_TEST(suite, test_attackers_get_no_building_bonus);
|
||||||
SUITE_ADD_TEST(suite, test_building_bonus_respects_size);
|
SUITE_ADD_TEST(suite, test_building_bonus_respects_size);
|
||||||
|
|
Loading…
Reference in New Issue