1+ import org.junit.jupiter.api.Assertions.assertTrue
2+ import org.junit.jupiter.api.Test
3+
4+ class YearUtilTest {
5+
6+ companion object {
7+ val LEAP_YEAR_LIST = arrayOf(1804 , 1808 , 1812 , 1816 , 1820 , 1824 , 1828 , 1832 , 1836 , 1840 , 1844 , 1848 , 1852 ,
8+ 1856 , 1860 , 1864 , 1868 , 1872 , 1876 , 1880 , 1884 , 1888 , 1892 , 1896 , 1904 , 1908 , 1912 , 1916 , 1920 , 1924 ,
9+ 1928 , 1932 , 1936 , 1940 , 1944 , 1948 , 1952 , 1956 , 1960 , 1964 , 1968 , 1972 , 1976 , 1980 , 1984 , 1988 , 1992 ,
10+ 1996 , 2000 , 2004 , 2008 , 2012 , 2016 , 2020 ,2024 , 2028 , 2032 , 2036 , 2040 , 2044 , 2048 , 2052 , 2056 , 2060 ,
11+ 2064 , 2068 , 2072 , 2076 , 2080 , 2084 , 2088 , 2092 , 2096
12+ )
13+ }
14+
15+ @Test
16+ fun `given leap years, then should properly mark them as such` () {
17+ // given
18+ var areAllLeapYears = true
19+
20+ // when
21+ LEAP_YEAR_LIST .forEach { year ->
22+ areAllLeapYears = areAllLeapYears and YearUtil .isLeapYear(year)
23+ }
24+
25+ // then
26+ assertTrue(areAllLeapYears)
27+ }
28+
29+ @Test
30+ fun `given non-leap years, then should properly mark them as such` () {
31+ // given
32+ var areAllNonLeapYears = true
33+
34+ // when
35+ LEAP_YEAR_LIST .forEachIndexed { index, currentLeapYear ->
36+ if (index == LEAP_YEAR_LIST .size - 1 ) {
37+ return @forEachIndexed
38+ }
39+ val nextLeapYear = LEAP_YEAR_LIST [index + 1 ]
40+ for (nonLeapYear in (currentLeapYear + 1 ) until nextLeapYear) {
41+ areAllNonLeapYears = areAllNonLeapYears and ! YearUtil .isLeapYear(nonLeapYear)
42+ }
43+ }
44+
45+ // then
46+ assertTrue(areAllNonLeapYears)
47+ }
48+
49+ }
0 commit comments