prepare for give_men refactoring by writing some basic tests.

This commit is contained in:
Enno Rehling 2014-12-10 20:44:33 +01:00
parent 1024dd5c81
commit 2a61dc4d11
2 changed files with 29 additions and 0 deletions

View File

@ -6,6 +6,7 @@
#include <kernel/config.h> #include <kernel/config.h>
#include <kernel/item.h> #include <kernel/item.h>
#include <kernel/terrain.h> #include <kernel/terrain.h>
#include <kernel/region.h>
#include <kernel/order.h> #include <kernel/order.h>
#include <kernel/unit.h> #include <kernel/unit.h>
#include <kernel/faction.h> #include <kernel/faction.h>
@ -35,6 +36,31 @@ static void setup_give(struct give *env) {
env->itype->flags |= ITF_HERB; env->itype->flags |= ITF_HERB;
} }
static void test_give_men(CuTest * tc) {
struct give env;
test_cleanup();
env.f2 = env.f1 = test_create_faction(0);
setup_give(&env);
give_men(1, env.src, env.dst, NULL);
CuAssertIntEquals(tc, 2, env.dst->number);
CuAssertIntEquals(tc, 0, env.src->number);
test_cleanup();
}
static void test_give_peasants(CuTest * tc) {
struct give env;
int peasants;
test_cleanup();
env.f2 = env.f1 = test_create_faction(0);
setup_give(&env);
peasants = env.r->land->peasants;
getunitpeasants = 1;
give_men(1, env.src, NULL, NULL);
CuAssertIntEquals(tc, 0, env.src->number);
CuAssertIntEquals(tc, peasants+1, env.r->land->peasants);
test_cleanup();
}
static void test_give(CuTest * tc) { static void test_give(CuTest * tc) {
struct give env; struct give env;
@ -110,6 +136,8 @@ CuSuite *get_give_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_give); SUITE_ADD_TEST(suite, test_give);
SUITE_ADD_TEST(suite, test_give_men);
SUITE_ADD_TEST(suite, test_give_peasants);
SUITE_ADD_TEST(suite, test_give_herbs); SUITE_ADD_TEST(suite, test_give_herbs);
SUITE_ADD_TEST(suite, test_give_okay); SUITE_ADD_TEST(suite, test_give_okay);
SUITE_ADD_TEST(suite, test_give_denied_by_rules); SUITE_ADD_TEST(suite, test_give_denied_by_rules);

View File

@ -172,6 +172,7 @@ race *rc_get_or_create(const char *zName)
rc = (race *)calloc(sizeof(race), 1); rc = (race *)calloc(sizeof(race), 1);
rc->hitpoints = 1; rc->hitpoints = 1;
rc->recruit_multi = 1.0F;
if (strchr(zName, ' ') != NULL) { if (strchr(zName, ' ') != NULL) {
log_error("race '%s' has an invalid name. remove spaces\n", zName); log_error("race '%s' has an invalid name. remove spaces\n", zName);
assert(strchr(zName, ' ') == NULL); assert(strchr(zName, ' ') == NULL);