forked from github/server
off-by-one error for early break from loop.
This commit is contained in:
parent
e5dc754c25
commit
8f802c11e1
|
@ -4128,7 +4128,7 @@ int armedmen(const unit * u, bool siege_weapons)
|
|||
if (effskill(u, wtype->skill, 0) >= wtype->minskill)
|
||||
n += itm->number;
|
||||
/* if (effskill(u, wtype->skill) >= wtype->minskill) n += itm->number; */
|
||||
if (n > u->number)
|
||||
if (n >= u->number)
|
||||
break;
|
||||
}
|
||||
n = _min(n, u->number);
|
||||
|
|
|
@ -1402,6 +1402,26 @@ static void test_demon_hunger(CuTest * tc)
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_armedmen(CuTest *tc) {
|
||||
unit *u;
|
||||
item_type *it_sword;
|
||||
test_setup();
|
||||
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||
it_sword = test_create_itemtype("sword");
|
||||
new_weapontype(it_sword, 0, 0.5, 0, 0, 0, 0, SK_MELEE, 1);
|
||||
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
||||
CuAssertIntEquals(tc, 0, armedmen(u, true));
|
||||
set_level(u, SK_MELEE, 1);
|
||||
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
||||
i_change(&u->items, it_sword, 1);
|
||||
CuAssertIntEquals(tc, 1, armedmen(u, false));
|
||||
i_change(&u->items, it_sword, 1);
|
||||
CuAssertIntEquals(tc, 1, armedmen(u, false));
|
||||
set_level(u, SK_MELEE, 0);
|
||||
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_laws_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
|
@ -1464,6 +1484,7 @@ CuSuite *get_laws_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_show_race);
|
||||
SUITE_ADD_TEST(suite, test_immigration);
|
||||
SUITE_ADD_TEST(suite, test_demon_hunger);
|
||||
SUITE_ADD_TEST(suite, test_armedmen);
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue