-
-
Notifications
You must be signed in to change notification settings - Fork 408
/
Copy pathIsLeapYear.test.ts
66 lines (58 loc) · 1.93 KB
/
IsLeapYear.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { IsLeapYear } from "../IsLeapYear";
describe("IsLeapYear", () => {
test.each([4, 8, 12, 2004])(
"a year is a leap year it is divisible by 4 but not by 400 like %i",
(year) => {
expect(year % 4 === 0).toBe(true);
expect(year % 400 === 0).toBe(false);
expect(IsLeapYear(year)).toBe(true);
},
);
test.each([400, 800, 1200, 1600, 2000, 2400, 40000])(
"a year is a leap year it is divisible by 400 like %i",
(year) => {
expect(year % 400 === 0).toBe(true);
expect(IsLeapYear(year)).toBe(true);
},
);
test.each([1, 313, 1997, 2001, 2021, 13337])(
"a year is not a leap year if it is not divisible by 4 like %i",
(year) => {
expect(year % 4 === 0).toBe(false);
expect(IsLeapYear(year)).toBe(false);
},
);
test.each([100, 200, 300, 700, 2100])(
"a year is not a leap year if it is divisible by 100 but not by 400 like %i",
(year) => {
expect(year % 100 === 0).toBe(true);
expect(year % 400 === 0).toBe(false);
expect(IsLeapYear(year)).toBe(false);
},
);
test.each([1, 2022, 3000000])(
"a year is supported if it is a natural number > 0 like %i",
(year) => {
expect(year > 0).toBe(true);
expect(Number.isInteger(year)).toBe(true);
expect(() => IsLeapYear(year)).not.toThrow();
},
);
test.each([-1, -10, -Infinity])(
"a year is not supported if it is negative like %i",
(year) => {
expect(year < 0).toBe(true);
expect(() => IsLeapYear(year)).toThrow("year must be a natural number > 0");
},
);
test.each([0.1, 1.2, 4.2])(
"a year is not supported if it is not an integer %d",
(year) => {
expect(Number.isInteger(year)).toBe(false);
expect(() => IsLeapYear(year)).toThrow("year must be a natural number > 0");
},
);
test("a year is not supported if it is 0", () => {
expect(() => IsLeapYear(0)).toThrow("year must be a natural number > 0");
})
});