also test changing persons

This commit is contained in:
Enno Rehling 2012-10-21 19:42:59 -07:00
parent 5e58f3a881
commit 79feb5723c
2 changed files with 35 additions and 13 deletions

View File

@ -73,7 +73,11 @@ static int res_changeaura(unit * u, const resource_type * rtype, int delta)
static int res_changeperson(unit * u, const resource_type * rtype, int delta)
{
assert(rtype != NULL || !"not implemented");
scale_number(u, u->number + delta);
if (u->number + delta >=0) {
scale_number(u, u->number + delta);
} else {
scale_number(u, 0);
}
return u->number;
}

View File

@ -2,6 +2,7 @@
#include <kernel/types.h>
#include <kernel/item.h>
#include <kernel/pool.h>
#include <kernel/unit.h>
#include <util/language.h>
#include <util/functions.h>
@ -9,26 +10,42 @@
#include <CuTest.h>
#include <tests.h>
static void test_uchange(CuTest * tc, unit * u, const resource_type * rtype) {
int n;
change_resource(u, rtype, 4);
n = get_resource(u, rtype);
CuAssertPtrNotNull(tc, rtype->uchange);
CuAssertIntEquals(tc, n, rtype->uchange(u, rtype, 0));
CuAssertIntEquals(tc, n-3, rtype->uchange(u, rtype, -3));
CuAssertIntEquals(tc, n-3, get_resource(u, rtype));
CuAssertIntEquals(tc, 0, rtype->uchange(u, rtype, -n));
}
void test_change_item(CuTest * tc)
{
rtype_uchange res_changeitem;
const resource_type * rtype;
unit * u;
register_resources();
res_changeitem = (rtype_uchange)get_function("changeitem");
CuAssertPtrNotNull(tc, res_changeitem);
test_cleanup();
register_resources();
init_resources();
test_create_world();
rtype = olditemtype[I_IRON]->rtype;
u = test_create_unit(0, 0);
CuAssertIntEquals(tc, 0, res_changeitem(u, rtype, 0));
i_change(&u->items, rtype->itype, 4);
CuAssertIntEquals(tc, 4, res_changeitem(u, rtype, 0));
CuAssertIntEquals(tc, 1, res_changeitem(u, rtype, -3));
CuAssertIntEquals(tc, 1, i_get(u->items, rtype->itype));
test_uchange(tc, u, olditemtype[I_IRON]->rtype);
}
void test_change_person(CuTest * tc)
{
unit * u;
test_cleanup();
register_resources();
init_resources();
test_create_world();
u = test_create_unit(0, 0);
test_uchange(tc, u, r_unit);
}
void test_resource_type(CuTest * tc)
@ -93,6 +110,7 @@ CuSuite *get_item_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_change_item);
SUITE_ADD_TEST(suite, test_change_person);
SUITE_ADD_TEST(suite, test_resource_type);
SUITE_ADD_TEST(suite, test_finditemtype);
SUITE_ADD_TEST(suite, test_findresourcetype);