Merge branch 'master' into develop

This commit is contained in:
Enno Rehling 2018-11-06 19:33:46 +01:00
commit e570300dbe
3 changed files with 54 additions and 6 deletions

2
clibs

@ -1 +1 @@
Subproject commit ed5c4fee3afbc3d8be79d64857f30702aed522f8
Subproject commit d80ba4b609c2aebf5bf38da60367dc0f0e2d50b9

View File

@ -94,11 +94,15 @@ void autostudy_run(scholar scholars[], int nscholars)
}
/* now si splits the teachers and students 1:10 */
/* first student must be 2 levels below first teacher: */
for (; si != se && scholars[ti].level - TEACHDIFFERENCE > scholars[si].level && scholars[si].sk == sk; ++si) {
for (; si != se && scholars[si].sk == sk; ++si) {
if (scholars[si].level + TEACHDIFFERENCE <= scholars[ti].level) {
break;
}
tt += scholars[si].u->number;
}
if (si == se) {
/* there are no students, so standard learning only */
/* now si is the first unit we can teach, if we can teach any */
if (si == se || scholars[si].sk != sk) {
/* there are no students, so standard learning for everyone */
for (t = ti; t != se; ++t) {
learning(scholars + t, scholars[t].u->number);
}
@ -109,7 +113,7 @@ void autostudy_run(scholar scholars[], int nscholars)
/* invariant: unit si has n students that can still be taught */
int n = scholars[si].u->number;
for (t = ti, s = si; t != si && s != se; ) {
if (i > n) {
if (i >= n) {
/* t has more than enough teaching capacity for s */
i -= n;
teaching(scholars + s, n);
@ -149,6 +153,15 @@ void autostudy_run(scholar scholars[], int nscholars)
i = scholars[t].u->number * STUDENTS_PER_TEACHER;
}
}
if (i > 0) {
int remain = (STUDENTS_PER_TEACHER * scholars[t].u->number - i + STUDENTS_PER_TEACHER - 1) / STUDENTS_PER_TEACHER;
/* teacher has remaining time */
learning(scholars + t, remain);
}
++t;
for (; t < si; ++t) {
learning(scholars + t, scholars[t].u->number);
}
}
ti = se;
}

View File

@ -91,7 +91,7 @@ static void test_autostudy_run(CuTest *tc) {
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, &ulist));
CuAssertPtrEquals(tc, NULL, ulist);
autostudy_run(scholars, 3);
CuAssertIntEquals(tc, 0, scholars[0].learn);
CuAssertIntEquals(tc, 1, scholars[0].learn);
CuAssertIntEquals(tc, 20, scholars[1].learn);
CuAssertIntEquals(tc, 15, scholars[2].learn);
test_teardown();
@ -127,11 +127,46 @@ static void test_autostudy_run_noteachers(CuTest *tc) {
test_teardown();
}
/**
* Reproduce Bug 2514
*/
static void test_autostudy_run_skilldiff(CuTest *tc) {
scholar scholars[4];
unit *u1, *u2, *u3, *ulist;
faction *f;
region *r;
test_setup();
r = test_create_plain(0, 0);
f = test_create_faction(NULL);
u1 = test_create_unit(f, r);
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
set_number(u1, 1);
set_level(u1, SK_PERCEPTION, 2);
u2 = test_create_unit(f, r);
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
set_number(u2, 10);
set_level(u2, SK_PERCEPTION, 1);
u3 = test_create_unit(f, r);
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
set_number(u3, 10);
scholars[3].u = NULL;
ulist = r->units;
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, &ulist));
CuAssertPtrEquals(tc, NULL, ulist);
autostudy_run(scholars, 3);
CuAssertIntEquals(tc, 0, scholars[0].learn);
CuAssertIntEquals(tc, 20, scholars[2].learn);
CuAssertIntEquals(tc, 10, scholars[1].learn);
test_teardown();
}
CuSuite *get_automate_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_autostudy_init);
SUITE_ADD_TEST(suite, test_autostudy_run);
SUITE_ADD_TEST(suite, test_autostudy_run_noteachers);
SUITE_ADD_TEST(suite, test_autostudy_run_skilldiff);
return suite;
}