server/src/calendar.test.c

99 lines
2.4 KiB
C
Raw Normal View History

2017-05-07 13:35:59 +02:00
#include <platform.h>
#include "calendar.h"
#include <kernel/config.h>
#include <CuTest.h>
#include "tests.h"
2017-05-07 13:40:43 +02:00
static void test_calendar_config(CuTest * tc)
{
gamedate gd;
test_setup();
get_gamedate(0, &gd);
CuAssertIntEquals(tc, 0, first_turn());
config_set_int("game.start", 42);
CuAssertIntEquals(tc, 42, first_turn());
test_cleanup();
}
2017-05-07 13:35:59 +02:00
static void test_calendar(CuTest * tc)
{
gamedate gd;
test_setup();
get_gamedate(0, &gd);
2017-05-07 13:40:43 +02:00
CuAssertIntEquals(tc, 1, gd.year);
CuAssertIntEquals(tc, 0, gd.season);
CuAssertIntEquals(tc, 0, gd.month);
CuAssertIntEquals(tc, 0, gd.week);
get_gamedate(1, &gd);
CuAssertIntEquals(tc, 1, gd.year);
CuAssertIntEquals(tc, 0, gd.season);
2017-05-07 13:35:59 +02:00
CuAssertIntEquals(tc, 0, gd.month);
2017-05-07 13:40:43 +02:00
CuAssertIntEquals(tc, 1, gd.week);
2017-05-07 15:50:19 +02:00
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);
2017-05-07 13:40:43 +02:00
config_set_int("game.start", 42);
get_gamedate(42, &gd);
CuAssertIntEquals(tc, 1, gd.year);
CuAssertIntEquals(tc, 0, gd.season);
CuAssertIntEquals(tc, 0, gd.month);
CuAssertIntEquals(tc, 0, gd.week);
2017-05-07 15:50:19 +02:00
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);
2017-05-07 13:35:59 +02:00
test_cleanup();
}
CuSuite *get_calendar_suite(void)
{
CuSuite *suite = CuSuiteNew();
2017-05-07 13:40:43 +02:00
SUITE_ADD_TEST(suite, test_calendar_config);
2017-05-07 13:35:59 +02:00
SUITE_ADD_TEST(suite, test_calendar);
2017-05-07 15:50:19 +02:00
SUITE_ADD_TEST(suite, test_calendar_season);
2017-05-07 13:35:59 +02:00
return suite;
}