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