learn_skill tests were unstable because of random progress (disable it)

This commit is contained in:
Enno Rehling 2016-03-13 19:13:58 +01:00
parent 18c8148b74
commit e75843e5c1
3 changed files with 11 additions and 8 deletions

View File

@ -848,12 +848,13 @@ bool learn_skill_depr(unit * u, skill_t sk, double learn_chance)
void learn_skill(unit *u, skill_t sk, int days) {
skill *sv = u->skills;
int leveldays = STUDYDAYS * u->number;
int weeks = 0;
while (days >= STUDYDAYS) {
while (days >= leveldays) {
++weeks;
days -= STUDYDAYS;
days -= leveldays;
}
if (days > 0 && rng_int() % STUDYDAYS < days) {
if (days > 0 && rng_int() % leveldays < days) {
++weeks;
}
if (weeks > 0 && !sv) {

View File

@ -234,6 +234,7 @@ void test_learn_skill_single(CuTest *tc) {
unit *u;
skill *sv;
test_cleanup();
config_set("study.random_progress", "0");
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
learn_skill(u, SK_ALCHEMY, STUDYDAYS);
CuAssertPtrNotNull(tc, sv = u->skills);
@ -244,7 +245,7 @@ void test_learn_skill_single(CuTest *tc) {
CuAssertIntEquals(tc, 1, sv->weeks);
learn_skill(u, SK_ALCHEMY, STUDYDAYS * 2);
CuAssertIntEquals(tc, 2, sv->level);
CuAssertIntEquals(tc, 1, sv->weeks);
CuAssertIntEquals(tc, 2, sv->weeks);
test_cleanup();
}
@ -252,7 +253,8 @@ void test_learn_skill_multi(CuTest *tc) {
unit *u;
skill *sv;
test_cleanup();
u = test_create_unit(0, 0);
config_set("study.random_progress", "0");
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
scale_number(u, 10);
learn_skill(u, SK_ALCHEMY, STUDYDAYS * u->number);
CuAssertPtrNotNull(tc, sv = u->skills);
@ -263,7 +265,7 @@ void test_learn_skill_multi(CuTest *tc) {
CuAssertIntEquals(tc, 1, sv->weeks);
learn_skill(u, SK_ALCHEMY, STUDYDAYS * u->number * 2);
CuAssertIntEquals(tc, 2, sv->level);
CuAssertIntEquals(tc, 1, sv->weeks);
CuAssertIntEquals(tc, 2, sv->weeks);
test_cleanup();
}

View File

@ -77,9 +77,9 @@ struct faction *test_create_faction(const struct race *rc)
struct unit *test_create_unit(struct faction *f, struct region *r)
{
const struct race * rc = f ? f->race : 0;
assert(f);
assert(f || !r);
if (!rc) rc = rc_get_or_create("human");
return create_unit(r, f, 1, rc, 0, 0, 0);
return create_unit(r, f, 1, rc ? rc : rc_get_or_create("human"), 0, 0, 0);
}
void test_cleanup(void)