forked from github/server
learn_skill tests were unstable because of random progress (disable it)
This commit is contained in:
parent
18c8148b74
commit
e75843e5c1
|
@ -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) {
|
void learn_skill(unit *u, skill_t sk, int days) {
|
||||||
skill *sv = u->skills;
|
skill *sv = u->skills;
|
||||||
|
int leveldays = STUDYDAYS * u->number;
|
||||||
int weeks = 0;
|
int weeks = 0;
|
||||||
while (days >= STUDYDAYS) {
|
while (days >= leveldays) {
|
||||||
++weeks;
|
++weeks;
|
||||||
days -= STUDYDAYS;
|
days -= leveldays;
|
||||||
}
|
}
|
||||||
if (days > 0 && rng_int() % STUDYDAYS < days) {
|
if (days > 0 && rng_int() % leveldays < days) {
|
||||||
++weeks;
|
++weeks;
|
||||||
}
|
}
|
||||||
if (weeks > 0 && !sv) {
|
if (weeks > 0 && !sv) {
|
||||||
|
|
|
@ -234,6 +234,7 @@ void test_learn_skill_single(CuTest *tc) {
|
||||||
unit *u;
|
unit *u;
|
||||||
skill *sv;
|
skill *sv;
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
config_set("study.random_progress", "0");
|
||||||
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||||
learn_skill(u, SK_ALCHEMY, STUDYDAYS);
|
learn_skill(u, SK_ALCHEMY, STUDYDAYS);
|
||||||
CuAssertPtrNotNull(tc, sv = u->skills);
|
CuAssertPtrNotNull(tc, sv = u->skills);
|
||||||
|
@ -244,7 +245,7 @@ void test_learn_skill_single(CuTest *tc) {
|
||||||
CuAssertIntEquals(tc, 1, sv->weeks);
|
CuAssertIntEquals(tc, 1, sv->weeks);
|
||||||
learn_skill(u, SK_ALCHEMY, STUDYDAYS * 2);
|
learn_skill(u, SK_ALCHEMY, STUDYDAYS * 2);
|
||||||
CuAssertIntEquals(tc, 2, sv->level);
|
CuAssertIntEquals(tc, 2, sv->level);
|
||||||
CuAssertIntEquals(tc, 1, sv->weeks);
|
CuAssertIntEquals(tc, 2, sv->weeks);
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +253,8 @@ void test_learn_skill_multi(CuTest *tc) {
|
||||||
unit *u;
|
unit *u;
|
||||||
skill *sv;
|
skill *sv;
|
||||||
test_cleanup();
|
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);
|
scale_number(u, 10);
|
||||||
learn_skill(u, SK_ALCHEMY, STUDYDAYS * u->number);
|
learn_skill(u, SK_ALCHEMY, STUDYDAYS * u->number);
|
||||||
CuAssertPtrNotNull(tc, sv = u->skills);
|
CuAssertPtrNotNull(tc, sv = u->skills);
|
||||||
|
@ -263,7 +265,7 @@ void test_learn_skill_multi(CuTest *tc) {
|
||||||
CuAssertIntEquals(tc, 1, sv->weeks);
|
CuAssertIntEquals(tc, 1, sv->weeks);
|
||||||
learn_skill(u, SK_ALCHEMY, STUDYDAYS * u->number * 2);
|
learn_skill(u, SK_ALCHEMY, STUDYDAYS * u->number * 2);
|
||||||
CuAssertIntEquals(tc, 2, sv->level);
|
CuAssertIntEquals(tc, 2, sv->level);
|
||||||
CuAssertIntEquals(tc, 1, sv->weeks);
|
CuAssertIntEquals(tc, 2, sv->weeks);
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,9 +77,9 @@ struct faction *test_create_faction(const struct race *rc)
|
||||||
struct unit *test_create_unit(struct faction *f, struct region *r)
|
struct unit *test_create_unit(struct faction *f, struct region *r)
|
||||||
{
|
{
|
||||||
const struct race * rc = f ? f->race : 0;
|
const struct race * rc = f ? f->race : 0;
|
||||||
assert(f);
|
assert(f || !r);
|
||||||
if (!rc) rc = rc_get_or_create("human");
|
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)
|
void test_cleanup(void)
|
||||||
|
|
Loading…
Reference in New Issue