forked from github/server
fleshing out the calendar tests
This commit is contained in:
parent
fa7e21b783
commit
29061fa4ba
|
@ -6,7 +6,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
int first_month = 0;
|
int first_month = 0;
|
||||||
int weeks_per_month = 4;
|
int weeks_per_month = 3;
|
||||||
int months_per_year = 12;
|
int months_per_year = 12;
|
||||||
char **seasonnames = NULL;
|
char **seasonnames = NULL;
|
||||||
char **weeknames = NULL;
|
char **weeknames = NULL;
|
||||||
|
@ -73,4 +73,8 @@ void calendar_cleanup(void)
|
||||||
weeknames = 0;
|
weeknames = 0;
|
||||||
free(weeknames2);
|
free(weeknames2);
|
||||||
weeknames2 = 0;
|
weeknames2 = 0;
|
||||||
|
|
||||||
|
first_month = 0;
|
||||||
|
weeks_per_month = 3;
|
||||||
|
months_per_year = 12;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,18 @@ static void test_calendar(CuTest * tc)
|
||||||
CuAssertIntEquals(tc, 0, gd.month);
|
CuAssertIntEquals(tc, 0, gd.month);
|
||||||
CuAssertIntEquals(tc, 1, gd.week);
|
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);
|
config_set_int("game.start", 42);
|
||||||
get_gamedate(42, &gd);
|
get_gamedate(42, &gd);
|
||||||
CuAssertIntEquals(tc, 1, gd.year);
|
CuAssertIntEquals(tc, 1, gd.year);
|
||||||
|
@ -43,6 +55,36 @@ static void test_calendar(CuTest * tc)
|
||||||
CuAssertIntEquals(tc, 0, gd.month);
|
CuAssertIntEquals(tc, 0, gd.month);
|
||||||
CuAssertIntEquals(tc, 0, gd.week);
|
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();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,5 +93,6 @@ CuSuite *get_calendar_suite(void)
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_calendar_config);
|
SUITE_ADD_TEST(suite, test_calendar_config);
|
||||||
SUITE_ADD_TEST(suite, test_calendar);
|
SUITE_ADD_TEST(suite, test_calendar);
|
||||||
|
SUITE_ADD_TEST(suite, test_calendar_season);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "keyword.h"
|
#include "keyword.h"
|
||||||
#include "prefix.h"
|
#include "prefix.h"
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
|
#include "calendar.h"
|
||||||
|
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include <kernel/alliance.h>
|
#include <kernel/alliance.h>
|
||||||
|
@ -206,6 +207,7 @@ static void test_reset(void) {
|
||||||
free_resources();
|
free_resources();
|
||||||
free_config();
|
free_config();
|
||||||
default_locale = 0;
|
default_locale = 0;
|
||||||
|
calendar_cleanup();
|
||||||
close_orders();
|
close_orders();
|
||||||
free_locales();
|
free_locales();
|
||||||
free_spells();
|
free_spells();
|
||||||
|
|
Loading…
Reference in New Issue