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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
#!/usr/bin/env raku
use Test;
use JSON::Fast;
use lib $?FILE.IO.dirname;
use Leap;
plan 9;
my @test-cases = from-json($=pod.pop.contents).List;
for Date, DateTime {
.^method_table<is-leap-year>.wrap: sub (|) {
bail-out 'Built-in `is-leap-year` method is not allowed for this exercise.';
};
}
for @test-cases -> %case {
subtest %case<description>, {
plan 2;
isa-ok ( my $result := is-leap-year %case<input><year> ), Bool;
is-deeply $result, %case<expected>, 'Result matches expected';
}
}
=head2 Test Cases
=begin code
[
{
"description": "year not divisible by 4 in common year",
"expected": false,
"input": {
"year": 2015
},
"property": "leapYear"
},
{
"description": "year divisible by 2, not divisible by 4 in common year",
"expected": false,
"input": {
"year": 1970
},
"property": "leapYear"
},
{
"description": "year divisible by 4, not divisible by 100 in leap year",
"expected": true,
"input": {
"year": 1996
},
"property": "leapYear"
},
{
"description": "year divisible by 4 and 5 is still a leap year",
"expected": true,
"input": {
"year": 1960
},
"property": "leapYear"
},
{
"description": "year divisible by 100, not divisible by 400 in common year",
"expected": false,
"input": {
"year": 2100
},
"property": "leapYear"
},
{
"description": "year divisible by 100 but not by 3 is still not a leap year",
"expected": false,
"input": {
"year": 1900
},
"property": "leapYear"
},
{
"description": "year divisible by 400 in leap year",
"expected": true,
"input": {
"year": 2000
},
"property": "leapYear"
},
{
"description": "year divisible by 400 but not by 125 is still a leap year",
"expected": true,
"input": {
"year": 2400
},
"property": "leapYear"
},
{
"description": "year divisible by 200, not divisible by 400 in common year",
"expected": false,
"input": {
"year": 1800
},
"property": "leapYear"
}
]
=end code
|