forked from github/server
add test for pool, fix a problem with (unused) feature that pools from allies.
This commit is contained in:
parent
e9c13cc328
commit
c8d5d52412
|
@ -167,7 +167,7 @@ int count)
|
||||||
|
|
||||||
if ((mode & GET_SLACK) && (mode & GET_RESERVE))
|
if ((mode & GET_SLACK) && (mode & GET_RESERVE))
|
||||||
use = have;
|
use = have;
|
||||||
else {
|
else if (mode & (GET_SLACK|GET_RESERVE)) {
|
||||||
int reserve = get_reservation(u, rtype);
|
int reserve = get_reservation(u, rtype);
|
||||||
int slack = _max(0, have - reserve);
|
int slack = _max(0, have - reserve);
|
||||||
if (mode & GET_RESERVE)
|
if (mode & GET_RESERVE)
|
||||||
|
|
|
@ -29,8 +29,8 @@ extern "C" {
|
||||||
#define GET_POOLED_SLACK 0x08
|
#define GET_POOLED_SLACK 0x08
|
||||||
#define GET_POOLED_RESERVE 0x10
|
#define GET_POOLED_RESERVE 0x10
|
||||||
#define GET_POOLED_FORCE 0x20 /* ignore f->options pools */
|
#define GET_POOLED_FORCE 0x20 /* ignore f->options pools */
|
||||||
#define GET_ALLIED_SLACK 0x30
|
#define GET_ALLIED_SLACK 0x40
|
||||||
#define GET_ALLIED_RESERVE 0x40
|
#define GET_ALLIED_RESERVE 0x80
|
||||||
|
|
||||||
/* for convenience: */
|
/* for convenience: */
|
||||||
#define GET_DEFAULT (GET_RESERVE|GET_SLACK|GET_POOLED_SLACK)
|
#define GET_DEFAULT (GET_RESERVE|GET_SLACK|GET_POOLED_SLACK)
|
||||||
|
|
|
@ -1,15 +1,63 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/types.h>
|
#include <kernel/types.h>
|
||||||
|
|
||||||
|
#include "ally.h"
|
||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
#include "magic.h"
|
#include "magic.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
#include "faction.h"
|
||||||
#include "region.h"
|
#include "region.h"
|
||||||
#include "skill.h"
|
#include "skill.h"
|
||||||
|
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
void test_pool(CuTest *tc) {
|
||||||
|
unit *u1, *u2, *u3;
|
||||||
|
faction *f;
|
||||||
|
region *r;
|
||||||
|
struct resource_type *rtype;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
rtype = rt_get_or_create("money");
|
||||||
|
it_get_or_create(rtype);
|
||||||
|
f = test_create_faction(0);
|
||||||
|
r = findregion(0, 0);
|
||||||
|
assert(r && f && rtype && rtype->itype);
|
||||||
|
u1 = test_create_unit(f, r);
|
||||||
|
u2 = test_create_unit(f, r);
|
||||||
|
u3 = test_create_unit(test_create_faction(0), r);
|
||||||
|
assert(u1 && u2);
|
||||||
|
i_change(&u1->items, rtype->itype, 100);
|
||||||
|
set_resvalue(u1, rtype, 50);
|
||||||
|
i_change(&u2->items, rtype->itype, 200);
|
||||||
|
set_resvalue(u2, rtype, 100);
|
||||||
|
i_change(&u3->items, rtype->itype, 400);
|
||||||
|
set_resvalue(u3, rtype, 200);
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 50, get_pooled(u1, rtype, GET_SLACK, 40));
|
||||||
|
CuAssertIntEquals(tc, 50, get_pooled(u1, rtype, GET_SLACK, INT_MAX));
|
||||||
|
CuAssertIntEquals(tc, 100, get_pooled(u1, rtype, GET_SLACK | GET_RESERVE, INT_MAX));
|
||||||
|
CuAssertIntEquals(tc, 150, get_pooled(u1, rtype, GET_SLACK | GET_POOLED_SLACK, INT_MAX));
|
||||||
|
CuAssertIntEquals(tc, 100, get_pooled(u1, rtype, GET_POOLED_SLACK, INT_MAX));
|
||||||
|
CuAssertIntEquals(tc, 200, get_pooled(u1, rtype, GET_POOLED_SLACK | GET_POOLED_RESERVE, INT_MAX));
|
||||||
|
|
||||||
|
u3->faction->allies = calloc(1, sizeof(ally));
|
||||||
|
u3->faction->allies->faction = f;
|
||||||
|
u3->faction->allies->status = HELP_GUARD;
|
||||||
|
CuAssertIntEquals(tc, 0, get_pooled(u1, rtype, GET_ALLIED_SLACK | GET_ALLIED_RESERVE, INT_MAX));
|
||||||
|
u3->faction->allies->status = HELP_MONEY;
|
||||||
|
CuAssertIntEquals(tc, 200, get_pooled(u1, rtype, GET_ALLIED_SLACK, INT_MAX));
|
||||||
|
CuAssertIntEquals(tc, 200, get_pooled(u1, rtype, GET_ALLIED_RESERVE, INT_MAX));
|
||||||
|
CuAssertIntEquals(tc, 400, get_pooled(u1, rtype, GET_ALLIED_SLACK | GET_ALLIED_RESERVE, INT_MAX));
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 100, get_pooled(u1, rtype, GET_ALL, 50));
|
||||||
|
CuAssertIntEquals(tc, 300, get_pooled(u1, rtype, GET_ALL, 150));
|
||||||
|
CuAssertIntEquals(tc, 300, get_pooled(u1, rtype, GET_ALL, INT_MAX));
|
||||||
|
}
|
||||||
|
|
||||||
void test_change_resource(CuTest * tc)
|
void test_change_resource(CuTest * tc)
|
||||||
{
|
{
|
||||||
|
@ -41,7 +89,7 @@ void test_change_resource(CuTest * tc)
|
||||||
CuSuite *get_pool_suite(void)
|
CuSuite *get_pool_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
/* SUITE_ADD_TEST(suite, test_pool); */
|
SUITE_ADD_TEST(suite, test_pool);
|
||||||
SUITE_ADD_TEST(suite, test_change_resource);
|
SUITE_ADD_TEST(suite, test_change_resource);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue