diff --git a/src/calendar.c b/src/calendar.c index d2a70c974..4c1534a27 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -6,7 +6,7 @@ #include int first_month = 0; -int weeks_per_month = 4; +int weeks_per_month = 3; int months_per_year = 12; char **seasonnames = NULL; char **weeknames = NULL; @@ -73,4 +73,8 @@ void calendar_cleanup(void) weeknames = 0; free(weeknames2); weeknames2 = 0; + + first_month = 0; + weeks_per_month = 3; + months_per_year = 12; } diff --git a/src/calendar.test.c b/src/calendar.test.c index 488db3bfe..e858747ec 100644 --- a/src/calendar.test.c +++ b/src/calendar.test.c @@ -36,6 +36,18 @@ static void test_calendar(CuTest * tc) CuAssertIntEquals(tc, 0, gd.month); CuAssertIntEquals(tc, 1, gd.week); + get_gamedate(weeks_per_month, &gd); + CuAssertIntEquals(tc, 1, gd.year); + CuAssertIntEquals(tc, 0, gd.season); + CuAssertIntEquals(tc, 1, gd.month); + CuAssertIntEquals(tc, 0, gd.week); + + get_gamedate(weeks_per_month*months_per_year, &gd); + CuAssertIntEquals(tc, 2, gd.year); + CuAssertIntEquals(tc, 0, gd.season); + CuAssertIntEquals(tc, 0, gd.month); + CuAssertIntEquals(tc, 0, gd.week); + config_set_int("game.start", 42); get_gamedate(42, &gd); CuAssertIntEquals(tc, 1, gd.year); @@ -43,6 +55,36 @@ static void test_calendar(CuTest * tc) CuAssertIntEquals(tc, 0, gd.month); CuAssertIntEquals(tc, 0, gd.week); + first_month = 2; + get_gamedate(42, &gd); + CuAssertIntEquals(tc, 1, gd.year); + CuAssertIntEquals(tc, 0, gd.season); + CuAssertIntEquals(tc, 2, gd.month); + CuAssertIntEquals(tc, 0, gd.week); + + test_cleanup(); +} + +static void test_calendar_season(CuTest * tc) +{ + gamedate gd; + + test_setup(); + month_season = calloc(months_per_year, sizeof(int)); + + get_gamedate(0, &gd); + CuAssertIntEquals(tc, 1, gd.year); + CuAssertIntEquals(tc, 0, gd.season); + CuAssertIntEquals(tc, 0, gd.month); + CuAssertIntEquals(tc, 0, gd.week); + + month_season[1] = 1; + get_gamedate(weeks_per_month + 1, &gd); + CuAssertIntEquals(tc, 1, gd.year); + CuAssertIntEquals(tc, 1, gd.season); + CuAssertIntEquals(tc, 1, gd.month); + CuAssertIntEquals(tc, 1, gd.week); + test_cleanup(); } @@ -51,5 +93,6 @@ CuSuite *get_calendar_suite(void) CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_calendar_config); SUITE_ADD_TEST(suite, test_calendar); + SUITE_ADD_TEST(suite, test_calendar_season); return suite; } diff --git a/src/tests.c b/src/tests.c index 19deb91ea..60447f5d8 100644 --- a/src/tests.c +++ b/src/tests.c @@ -3,6 +3,7 @@ #include "keyword.h" #include "prefix.h" #include "reports.h" +#include "calendar.h" #include #include @@ -206,6 +207,7 @@ static void test_reset(void) { free_resources(); free_config(); default_locale = 0; + calendar_cleanup(); close_orders(); free_locales(); free_spells();