From e5e936acc6bd0b361ba71e1897cb692ffbac1795 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 21 Feb 2020 21:12:19 +0100 Subject: [PATCH] =?UTF-8?q?Bug=202640:=20LERNE=20AUTO=20sollte=20nicht=20a?= =?UTF-8?q?lle=20Einheiten=20zu=20Lehrern=20delegieren.=20Fixt=20den=20kon?= =?UTF-8?q?kreten=20Bug,=20f=C3=BChlt=20sich=20aber=20immer=20noch=20nach?= =?UTF-8?q?=20einemn=20Spezialfall=20an=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/automate.c | 2 +- src/automate.test.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/automate.c b/src/automate.c index 2c9a94ad0..960c67a4c 100644 --- a/src/automate.c +++ b/src/automate.c @@ -96,7 +96,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; ++si) { + for (; mint > tt && si != nscholars - 1; ++si) { tt += scholars[si].u->number; } } diff --git a/src/automate.test.c b/src/automate.test.c index 5508cce88..adb4c1da7 100644 --- a/src/automate.test.c +++ b/src/automate.test.c @@ -110,6 +110,40 @@ static void test_autostudy_run_twoteachers(CuTest *tc) { test_teardown(); } +/** + * Reproduce Bug 2640 + */ +static void test_autostudy_run_bigunit(CuTest *tc) { + scholar scholars[4]; + int nscholars; + unit *u1, *u2, *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, 1000); + set_level(u2, SK_ENTERTAINMENT, 10); + u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]); + + ulist = r->units; + CuAssertIntEquals(tc, 2, 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, 200, scholars[1].learn); + + test_teardown(); +} + static void test_autostudy_run(CuTest *tc) { scholar scholars[4]; int nscholars; @@ -325,6 +359,7 @@ CuSuite *get_automate_suite(void) SUITE_ADD_TEST(suite, test_autostudy_run_noteachers); 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_skilldiff); return suite; }