forked from github/server
add a unit test for academy_can_teach.
This commit is contained in:
parent
79b5464aab
commit
c23e7bf9b9
|
@ -201,6 +201,7 @@ target_link_libraries(convert
|
|||
set(TESTS_SRC
|
||||
test_eressea.c
|
||||
tests.c
|
||||
academy.test.c
|
||||
alchemy.test.c
|
||||
battle.test.c
|
||||
calendar.test.c
|
||||
|
|
|
@ -36,8 +36,8 @@ void academy_teaching_bonus(struct unit *u, skill_t sk, int students) {
|
|||
bool academy_can_teach(unit *teacher, unit *student, skill_t sk) {
|
||||
const struct building_type *btype = bt_find("academy");
|
||||
if (active_building(teacher, btype) && active_building(student, btype)) {
|
||||
int j = study_cost(student, sk);
|
||||
j = MAX(50, j * 2);
|
||||
int j = study_cost(student, sk) * 2;
|
||||
if (j < 50) j = 50;
|
||||
/* kann Einheit das zahlen? */
|
||||
return get_pooled(student, get_resourcetype(R_SILVER), GET_DEFAULT, j) >= j;
|
||||
/* sonst nehmen sie nicht am Unterricht teil */
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
#include <platform.h>
|
||||
|
||||
#include "academy.h"
|
||||
#include "skill.h"
|
||||
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/region.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
#include "tests.h"
|
||||
|
||||
static void test_academy(CuTest * tc)
|
||||
{
|
||||
faction *f;
|
||||
unit *u, *u2;
|
||||
region *r;
|
||||
building *b;
|
||||
const item_type *it_silver;
|
||||
|
||||
test_setup();
|
||||
config_set_int("skills.cost.alchemy", 100);
|
||||
r = test_create_region(0, 0, NULL);
|
||||
f = test_create_faction(NULL);
|
||||
u = test_create_unit(f, r);
|
||||
b = test_create_building(r, test_create_buildingtype("academy"));
|
||||
u2 = test_create_unit(f, r);
|
||||
it_silver = test_create_silver();
|
||||
|
||||
CuAssert(tc, "teacher must be in academy", !academy_can_teach(u, u2, SK_CROSSBOW));
|
||||
u_set_building(u, b);
|
||||
CuAssert(tc, "student must be in academy", !academy_can_teach(u, u2, SK_CROSSBOW));
|
||||
u_set_building(u2, b);
|
||||
CuAssert(tc, "student must have 50 silver", !academy_can_teach(u, u2, SK_CROSSBOW));
|
||||
i_change(&u2->items, it_silver, 50);
|
||||
CuAssert(tc, "building must be maintained", !academy_can_teach(u, u2, SK_CROSSBOW));
|
||||
b->flags |= BLD_MAINTAINED;
|
||||
CuAssert(tc, "building must have capacity", !academy_can_teach(u, u2, SK_CROSSBOW));
|
||||
b->size = 2;
|
||||
CuAssertTrue(tc, academy_can_teach(u, u2, SK_CROSSBOW));
|
||||
|
||||
CuAssert(tc, "student must pay skillcost", !academy_can_teach(u, u2, SK_ALCHEMY));
|
||||
i_change(&u2->items, it_silver, 150);
|
||||
CuAssertTrue(tc, academy_can_teach(u, u2, SK_ALCHEMY));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
CuSuite *get_academy_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_academy);
|
||||
return suite;
|
||||
}
|
|
@ -130,9 +130,14 @@ bool magic_lowskill(unit * u)
|
|||
|
||||
int study_cost(unit * u, skill_t sk)
|
||||
{
|
||||
static int config;
|
||||
static int cost[MAXSKILLS];
|
||||
int stufe, k = 50;
|
||||
|
||||
if (config_changed(&config)) {
|
||||
memset(cost, 0, sizeof(cost));
|
||||
}
|
||||
|
||||
if (cost[sk] == 0) {
|
||||
char buffer[256];
|
||||
sprintf(buffer, "skills.cost.%s", skillnames[sk]);
|
||||
|
|
|
@ -107,6 +107,7 @@ int RunAllTests(int argc, char *argv[])
|
|||
ADD_SUITE(familiar);
|
||||
ADD_SUITE(item);
|
||||
ADD_SUITE(magic);
|
||||
ADD_SUITE(academy);
|
||||
ADD_SUITE(alchemy);
|
||||
ADD_SUITE(reports);
|
||||
ADD_SUITE(region);
|
||||
|
|
Loading…
Reference in New Issue