13 #define assert_dt_eq(x, ...) assert_dt_eq_fn( LOCATION( #x " == " #__VA_ARGS__ ), x, __VA_ARGS__) 14 void assert_dt_eq_fn(
Location l,
const int* val,
int ye,
int mo=-1,
int da=-1,
int ho=-1,
int mi=-1,
int se=-1 )
16 int cmp[6] = { ye, mo, da, ho, mi, se };
31 static inline void normalN(
int& lo,
int& hi,
int N)
38 lo = (lo + (m*N)) % N;
45 #define assert_nn_eq(x, y, N, x1, y1) assert_nn_eq_fn( LOCATION( #x ", " #y " mod " #N " == " #x1 ", " #y1 ), x, y, N, x1, y1) 46 void assert_nn_eq_fn(
Location l,
int x,
int y,
int N,
int x1,
int y1)
52 if (vx == x1 && vy == y1)
57 << vx <<
", " << vy <<
"] != [" 58 << x1 <<
", " << y1 <<
"] instead";
62 struct TestGrcalDate {
63 void fill(
int* dst,
int ye,
int mo=-1,
int da=-1,
int ho=-1,
int mi=-1,
int se=-1)
131 fill(val, 2008, 3, 31);
133 fill(val, 2008, 3, 31, 3);
135 fill(val, 2008, 3, 31, 3, 21);
137 fill(val, 2008, 3, 31, 3, 21, 0);
156 fill(val, 2008, 1, 1, 0, 0, 0);
160 fill(val, 2008, 1, 1, 0, 0, 0);
165 fill(val, 2008, 3, 1, 0, 0, 0);
170 fill(val, 2008, 2, 28, 23, 0, 0);
175 fill(val, 2008, 2, 28, 23, 0, 0);
181 fill(val, 2008, 2, 28, 23, 0, 0);
209 fill(val1, 2007, 12, 25);
210 fill(val2, 2007, 12, 26);
214 fill(val1, 2007, 1, 2, 3, 4, 5);
217 fill(val2, 2007, 1, 1, 0, 0, 0);
220 fill(val2, 2006, 12, 31, 23, 59, 59);
223 fill(val1, 2006, 12, 31, 23, 59, 59);
224 fill(val2, 2007, 1, 2, 3, 4, 5);
229 struct TestGrcalTime {
230 void fill(
int* dst,
int ho=-1,
int mi=-1,
int se=-1)
246 fill(val, 11, 10, 9);
long long int duration(const int *begin, const int *end)
Give the duration in seconds of the interval between begin and end.
Definition: grcal.cpp:245
long long int secondsfrom(int year, const int *val)
Convert the given time in seconds elapsed since the beginning of the given year.
Definition: grcal.cpp:229
void Test
Definition: test.h:178
#define assert_eq(x, y)
Definition: test.h:33
This header provides functions to handle Gregorian calendar dates and times.
void upperbound(const int *src, int *dst)
Make a copy of the datetime, filling in missing values with the highest possible value they can have...
Definition: grcal.cpp:191
void easter(int year, int *month, int *day)
Compute the day of Easter.
Definition: grcal.cpp:91
#define assert_nn_eq(x, y, N, x1, y1)
Definition: grcal.test.h:45
std::string tostring(const int *val)
Convert a datetime to a string.
Definition: grcal.cpp:319
void normalise(int *res)
Normalise a datetime, in place.
Definition: grcal.cpp:145
void lowerbound(const int *src, int *dst)
Make a copy of the datetime, filling in missing values with the lowest possible value they can have...
Definition: grcal.cpp:112
int daysinmonth(int year, int month)
Return the number of days in a month.
Definition: grcal.cpp:57
#define assert_dt_eq(x,...)
Definition: grcal.test.h:13
int daysinyear(int year)
Return the number of days in a year.
Definition: grcal.cpp:84