study/teach: testing some easy edge cases

This commit is contained in:
Enno Rehling 2016-03-23 12:13:29 +01:00
parent 267dafcee5
commit 3aa110cfe6
1 changed files with 44 additions and 2 deletions

View File

@ -305,7 +305,27 @@ static void test_study_cmd(CuTest *tc) {
learn_reset(); learn_reset();
CuAssertPtrEquals(tc, u, log_learners[0].u); CuAssertPtrEquals(tc, u, log_learners[0].u);
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk); CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
CuAssertIntEquals(tc, 30, log_learners[0].days); CuAssertIntEquals(tc, STUDYDAYS, log_learners[0].days);
test_cleanup();
}
static void test_study_cost(CuTest *tc) {
unit *u;
const struct item_type *itype;
test_cleanup();
init_resources();
itype = get_resourcetype(R_SILVER)->itype;
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
scale_number(u, 2);
u->thisorder = create_order(K_STUDY, u->faction->locale, "ALCHEMY");
i_change(&u->items, itype, u->number * study_cost(u, SK_ALCHEMY));
learn_inject();
study_cmd(u, u->thisorder);
learn_reset();
CuAssertPtrEquals(tc, u, log_learners[0].u);
CuAssertIntEquals(tc, SK_ALCHEMY, log_learners[0].sk);
CuAssertIntEquals(tc, STUDYDAYS*u->number, log_learners[0].days);
CuAssertIntEquals(tc, 0, i_get(u->items, itype));
test_cleanup(); test_cleanup();
} }
@ -325,7 +345,27 @@ static void test_teach_cmd(CuTest *tc) {
learn_reset(); learn_reset();
CuAssertPtrEquals(tc, u, log_learners[0].u); CuAssertPtrEquals(tc, u, log_learners[0].u);
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk); CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
CuAssertIntEquals(tc, 600, log_learners[0].days); CuAssertIntEquals(tc, STUDYDAYS*2*u->number, log_learners[0].days);
test_cleanup();
}
static void test_teach_too_many(CuTest *tc) {
unit *u, *ut;
test_cleanup();
init_resources();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
scale_number(u, 20);
u->thisorder = create_order(K_STUDY, u->faction->locale, "CROSSBOW");
ut = test_create_unit(u->faction, u->region);
set_level(ut, SK_CROSSBOW, TEACHDIFFERENCE);
ut->thisorder = create_order(K_TEACH, u->faction->locale, itoa36(u->no));
learn_inject();
teach_cmd(ut, ut->thisorder);
study_cmd(u, u->thisorder);
learn_reset();
CuAssertPtrEquals(tc, u, log_learners[0].u);
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
CuAssertIntEquals(tc, STUDYDAYS * 10 + STUDYDAYS * u->number, log_learners[0].days);
test_cleanup(); test_cleanup();
} }
@ -333,7 +373,9 @@ CuSuite *get_study_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_study_cmd); SUITE_ADD_TEST(suite, test_study_cmd);
SUITE_ADD_TEST(suite, test_study_cost);
SUITE_ADD_TEST(suite, test_teach_cmd); SUITE_ADD_TEST(suite, test_teach_cmd);
SUITE_ADD_TEST(suite, test_teach_too_many);
SUITE_ADD_TEST(suite, test_learn_skill_single); SUITE_ADD_TEST(suite, test_learn_skill_single);
SUITE_ADD_TEST(suite, test_learn_skill_multi); SUITE_ADD_TEST(suite, test_learn_skill_multi);
SUITE_ADD_TEST(suite, test_study_no_teacher); SUITE_ADD_TEST(suite, test_study_no_teacher);