From 2a61dc4d1187d9c9ad229ec4a8be2da9ab97f7ad Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 10 Dec 2014 20:44:33 +0100 Subject: [PATCH] prepare for give_men refactoring by writing some basic tests. --- src/give.test.c | 28 ++++++++++++++++++++++++++++ src/kernel/race.c | 1 + 2 files changed, 29 insertions(+) diff --git a/src/give.test.c b/src/give.test.c index ea5237e65..fa5918fb5 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,31 @@ static void setup_give(struct give *env) { 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) { struct give env; @@ -110,6 +136,8 @@ CuSuite *get_give_suite(void) { CuSuite *suite = CuSuiteNew(); 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_okay); SUITE_ADD_TEST(suite, test_give_denied_by_rules); diff --git a/src/kernel/race.c b/src/kernel/race.c index e83183564..7452fe79d 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -172,6 +172,7 @@ race *rc_get_or_create(const char *zName) rc = (race *)calloc(sizeof(race), 1); rc->hitpoints = 1; + rc->recruit_multi = 1.0F; if (strchr(zName, ' ') != NULL) { log_error("race '%s' has an invalid name. remove spaces\n", zName); assert(strchr(zName, ' ') == NULL);