forked from rickar/cal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathholiday_defs_test.go
More file actions
78 lines (68 loc) · 2 KB
/
Copy pathholiday_defs_test.go
File metadata and controls
78 lines (68 loc) · 2 KB
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
// (c) 2017 Rick Arnold. Licensed under the BSD license (see LICENSE).
package cal
import (
"testing"
"time"
)
func TestCalculateEaster(t *testing.T) {
tests := []struct {
t time.Time
want bool
}{
{time.Date(2016, 3, 27, 0, 0, 0, 0, time.UTC), true},
{time.Date(2017, 4, 16, 0, 0, 0, 0, time.UTC), true},
{time.Date(2018, 4, 1, 0, 0, 0, 0, time.UTC), true},
{time.Date(2019, 4, 21, 0, 0, 0, 0, time.UTC), true},
{time.Date(2020, 4, 12, 0, 0, 0, 0, time.UTC), true},
{time.Date(2021, 4, 4, 0, 0, 0, 0, time.UTC), true},
}
for _, test := range tests {
easter := calculateEaster(test.t.Year(), test.t.Location())
got := (test.t == easter)
if got != test.want {
t.Errorf("got: %t; want: %t (%s)", got, test.want, test.t)
}
}
}
func TestCalculateGoodFriday(t *testing.T) {
c := NewCalendar()
c.AddHoliday(ECBGoodFriday)
tests := []struct {
t time.Time
want bool
}{
{time.Date(2016, 3, 25, 0, 0, 0, 0, time.UTC), true},
{time.Date(2017, 4, 14, 0, 0, 0, 0, time.UTC), true},
{time.Date(2018, 3, 30, 0, 0, 0, 0, time.UTC), true},
{time.Date(2019, 4, 19, 0, 0, 0, 0, time.UTC), true},
{time.Date(2020, 4, 10, 0, 0, 0, 0, time.UTC), true},
{time.Date(2021, 4, 2, 0, 0, 0, 0, time.UTC), true},
}
for _, test := range tests {
got := c.IsHoliday(test.t)
if got != test.want {
t.Errorf("got: %t; want: %t (%s)", got, test.want, test.t)
}
}
}
func TestCalculateEasterMonday(t *testing.T) {
c := NewCalendar()
c.AddHoliday(ECBEasterMonday)
tests := []struct {
t time.Time
want bool
}{
{time.Date(2016, 3, 28, 0, 0, 0, 0, time.UTC), true},
{time.Date(2017, 4, 17, 0, 0, 0, 0, time.UTC), true},
{time.Date(2018, 4, 2, 0, 0, 0, 0, time.UTC), true},
{time.Date(2019, 4, 22, 0, 0, 0, 0, time.UTC), true},
{time.Date(2020, 4, 13, 0, 0, 0, 0, time.UTC), true},
{time.Date(2021, 4, 5, 0, 0, 0, 0, time.UTC), true},
}
for _, test := range tests {
got := c.IsHoliday(test.t)
if got != test.want {
t.Errorf("got: %t; want: %t (%s)", got, test.want, test.t)
}
}
}