xref: /netbsd-src/external/bsd/ntp/dist/tests/libntp/ymd2yd.c (revision cdfa2a7ef92791ba9db70a584a1d904730e6fb46)
1*cdfa2a7eSchristos /*	$NetBSD: ymd2yd.c,v 1.2 2020/05/25 20:47:36 christos Exp $	*/
2067f5680Schristos 
3f17b710fSchristos #include "config.h"
4f17b710fSchristos 
5f17b710fSchristos #include "ntp_stdlib.h"
6f17b710fSchristos 
7f17b710fSchristos #include "unity.h"
8f17b710fSchristos 
9a6f3f22fSchristos void test_NonLeapYearFebruary(void);
10a6f3f22fSchristos void test_NonLeapYearJune(void);
11a6f3f22fSchristos void test_LeapYearFebruary(void);
12a6f3f22fSchristos void test_LeapYearDecember(void);
13f17b710fSchristos 
14f17b710fSchristos 
15a6f3f22fSchristos void
test_NonLeapYearFebruary(void)16a6f3f22fSchristos test_NonLeapYearFebruary(void) {
17f17b710fSchristos 	TEST_ASSERT_EQUAL(31 + 20, ymd2yd(2010, 2, 20)); //2010-02-20
18f17b710fSchristos }
19f17b710fSchristos 
20a6f3f22fSchristos 
21a6f3f22fSchristos void
test_NonLeapYearJune(void)22a6f3f22fSchristos test_NonLeapYearJune(void) {
23f17b710fSchristos 	int expected = 31+28+31+30+31+18; // 18 June non-leap year
24f17b710fSchristos 	TEST_ASSERT_EQUAL(expected, ymd2yd(2011, 6, 18));
25f17b710fSchristos }
26f17b710fSchristos 
27a6f3f22fSchristos 
28a6f3f22fSchristos void
test_LeapYearFebruary(void)29a6f3f22fSchristos test_LeapYearFebruary(void) {
30f17b710fSchristos 	TEST_ASSERT_EQUAL(31 + 20, ymd2yd(2012, 2, 20)); //2012-02-20 (leap year)
31f17b710fSchristos }
32f17b710fSchristos 
33a6f3f22fSchristos 
34a6f3f22fSchristos void
test_LeapYearDecember(void)35a6f3f22fSchristos test_LeapYearDecember(void) {
36f17b710fSchristos 	// 2012-12-31
37f17b710fSchristos 	int expected = 31+29+31+30+31+30+31+31+30+31+30+31;
38f17b710fSchristos 	TEST_ASSERT_EQUAL(expected, ymd2yd(2012, 12, 31));
39f17b710fSchristos }
40