forked from github/server
LERNE AUTO: fix tests and logic some more.
still haven't fixed the actual bug, algorithm is wrong.
This commit is contained in:
parent
e5e936acc6
commit
6ecd172ff4
|
@ -77,7 +77,8 @@ int autostudy_init(scholar scholars[], int max_scholars, unit **units, skill_t *
|
|||
|
||||
static void teaching(scholar *s, int n) {
|
||||
assert(n <= s->u->number);
|
||||
s->learn += n;
|
||||
// doppelter Effekt mit Lehrer:
|
||||
s->learn += n * 2;
|
||||
s->u->flags |= UFL_LONGACTION;
|
||||
}
|
||||
|
||||
|
@ -96,7 +97,7 @@ void autostudy_run(scholar scholars[], int nscholars)
|
|||
int mint;
|
||||
ts += scholars[se].u->number; /* count total scholars */
|
||||
mint = (ts + 10) / 11; /* need a minimum of ceil(ts/11) teachers */
|
||||
for (; mint > tt && si != nscholars - 1; ++si) {
|
||||
for (; mint > tt && si != nscholars; ++si) {
|
||||
tt += scholars[si].u->number;
|
||||
}
|
||||
}
|
||||
|
@ -125,10 +126,10 @@ void autostudy_run(scholar scholars[], int nscholars)
|
|||
/* t has more than enough teaching capacity for s */
|
||||
i -= n;
|
||||
teaching(scholars + s, n);
|
||||
learning(scholars + s, scholars[s].u->number);
|
||||
/* next student, please: */
|
||||
if (++s == se) {
|
||||
continue;
|
||||
/* no more students */
|
||||
break;
|
||||
}
|
||||
n = scholars[s].u->number;
|
||||
}
|
||||
|
@ -163,8 +164,13 @@ void autostudy_run(scholar scholars[], int nscholars)
|
|||
}
|
||||
++t;
|
||||
for (; t < si; ++t) {
|
||||
/* teachers that did not teach */
|
||||
learning(scholars + t, scholars[t].u->number);
|
||||
}
|
||||
for (; s < se; ++s) {
|
||||
/* students that were not taught */
|
||||
learning(scholars + s, scholars[s].u->number);
|
||||
}
|
||||
}
|
||||
ti = se;
|
||||
}
|
||||
|
|
|
@ -139,7 +139,43 @@ static void test_autostudy_run_bigunit(CuTest *tc) {
|
|||
autostudy_run(scholars, nscholars);
|
||||
CuAssertIntEquals(tc, SK_ENTERTAINMENT, skill);
|
||||
CuAssertIntEquals(tc, 0, scholars[0].learn);
|
||||
CuAssertIntEquals(tc, 200, scholars[1].learn);
|
||||
CuAssertIntEquals(tc, 1200, scholars[1].learn);
|
||||
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
static void test_autostudy_run_few_teachers(CuTest *tc) {
|
||||
scholar scholars[4];
|
||||
int nscholars;
|
||||
unit *u1, *u2, *u3, *ulist;
|
||||
faction *f;
|
||||
region *r;
|
||||
skill_t skill;
|
||||
|
||||
test_setup();
|
||||
r = test_create_plain(0, 0);
|
||||
f = test_create_faction(NULL);
|
||||
u1 = test_create_unit(f, r);
|
||||
set_number(u1, 20);
|
||||
set_level(u1, SK_ENTERTAINMENT, 16);
|
||||
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
|
||||
u2 = test_create_unit(f, r);
|
||||
set_number(u2, 500);
|
||||
set_level(u2, SK_ENTERTAINMENT, 10);
|
||||
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
|
||||
u3 = test_create_unit(f, r);
|
||||
set_number(u3, 100);
|
||||
set_level(u3, SK_ENTERTAINMENT, 10);
|
||||
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
|
||||
|
||||
ulist = r->units;
|
||||
CuAssertIntEquals(tc, 3, nscholars = autostudy_init(scholars, 4, &ulist, &skill));
|
||||
CuAssertPtrEquals(tc, NULL, ulist);
|
||||
autostudy_run(scholars, nscholars);
|
||||
CuAssertIntEquals(tc, SK_ENTERTAINMENT, skill);
|
||||
CuAssertIntEquals(tc, 0, scholars[0].learn);
|
||||
CuAssertIntEquals(tc, 100, scholars[1].learn);
|
||||
CuAssertIntEquals(tc, 700, scholars[2].learn);
|
||||
|
||||
test_teardown();
|
||||
}
|
||||
|
@ -360,6 +396,7 @@ CuSuite *get_automate_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_autostudy_run_teachers_learn);
|
||||
SUITE_ADD_TEST(suite, test_autostudy_run_twoteachers);
|
||||
SUITE_ADD_TEST(suite, test_autostudy_run_bigunit);
|
||||
SUITE_ADD_TEST(suite, test_autostudy_run_few_teachers);
|
||||
SUITE_ADD_TEST(suite, test_autostudy_run_skilldiff);
|
||||
return suite;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue