forked from github/server
also test changing persons
This commit is contained in:
parent
5e58f3a881
commit
79feb5723c
|
@ -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)
|
static int res_changeperson(unit * u, const resource_type * rtype, int delta)
|
||||||
{
|
{
|
||||||
assert(rtype != NULL || !"not implemented");
|
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;
|
return u->number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <kernel/types.h>
|
#include <kernel/types.h>
|
||||||
#include <kernel/item.h>
|
#include <kernel/item.h>
|
||||||
|
#include <kernel/pool.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
#include <util/functions.h>
|
#include <util/functions.h>
|
||||||
|
@ -9,26 +10,42 @@
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
#include <tests.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)
|
void test_change_item(CuTest * tc)
|
||||||
{
|
{
|
||||||
rtype_uchange res_changeitem;
|
|
||||||
const resource_type * rtype;
|
|
||||||
unit * u;
|
unit * u;
|
||||||
|
|
||||||
register_resources();
|
|
||||||
res_changeitem = (rtype_uchange)get_function("changeitem");
|
|
||||||
CuAssertPtrNotNull(tc, res_changeitem);
|
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
register_resources();
|
||||||
|
init_resources();
|
||||||
test_create_world();
|
test_create_world();
|
||||||
rtype = olditemtype[I_IRON]->rtype;
|
|
||||||
|
|
||||||
u = test_create_unit(0, 0);
|
u = test_create_unit(0, 0);
|
||||||
CuAssertIntEquals(tc, 0, res_changeitem(u, rtype, 0));
|
test_uchange(tc, u, olditemtype[I_IRON]->rtype);
|
||||||
i_change(&u->items, rtype->itype, 4);
|
}
|
||||||
CuAssertIntEquals(tc, 4, res_changeitem(u, rtype, 0));
|
|
||||||
CuAssertIntEquals(tc, 1, res_changeitem(u, rtype, -3));
|
void test_change_person(CuTest * tc)
|
||||||
CuAssertIntEquals(tc, 1, i_get(u->items, rtype->itype));
|
{
|
||||||
|
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)
|
void test_resource_type(CuTest * tc)
|
||||||
|
@ -93,6 +110,7 @@ CuSuite *get_item_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_change_item);
|
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_resource_type);
|
||||||
SUITE_ADD_TEST(suite, test_finditemtype);
|
SUITE_ADD_TEST(suite, test_finditemtype);
|
||||||
SUITE_ADD_TEST(suite, test_findresourcetype);
|
SUITE_ADD_TEST(suite, test_findresourcetype);
|
||||||
|
|
Loading…
Reference in New Issue