-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoliday_test.go
145 lines (134 loc) · 3.48 KB
/
goliday_test.go
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package goliday
import (
"testing"
"time"
)
func TestHolidays(t *testing.T) {
tests := []struct {
options []Option
expected holidays
}{
{
options: []Option{WithYear(2050)},
expected: holidays{
&holiday{year: 2050, month: 1, day: 1},
&holiday{year: 2050, month: 1, day: 10},
&holiday{year: 2050, month: 2, day: 11},
&holiday{year: 2050, month: 2, day: 23},
&holiday{year: 2050, month: 3, day: 20},
&holiday{year: 2050, month: 3, day: 21},
&holiday{year: 2050, month: 4, day: 29},
&holiday{year: 2050, month: 5, day: 3},
&holiday{year: 2050, month: 5, day: 4},
&holiday{year: 2050, month: 5, day: 5},
&holiday{year: 2050, month: 7, day: 18},
&holiday{year: 2050, month: 8, day: 11},
&holiday{year: 2050, month: 9, day: 19},
&holiday{year: 2050, month: 9, day: 23},
&holiday{year: 2050, month: 10, day: 10},
&holiday{year: 2050, month: 11, day: 3},
&holiday{year: 2050, month: 11, day: 23},
},
},
{
options: []Option{WithYear(2050), WithMonth(1)},
expected: holidays{
&holiday{year: 2050, month: 1, day: 1},
&holiday{year: 2050, month: 1, day: 10},
},
},
{
options: []Option{WithYear(2050), WithDay(11)},
expected: holidays{
&holiday{year: 2050, month: 2, day: 11},
&holiday{year: 2050, month: 8, day: 11},
},
},
{
options: []Option{WithTime(func() *time.Time {
loc, _ := time.LoadLocation("Asia/Tokyo")
t := time.Date(2050, 11, 23, 8, 4, 18, 0, loc)
return &t
}())},
expected: holidays{
&holiday{year: 2050, month: 11, day: 23},
},
},
{
options: []Option{WithYear(1)},
expected: holidays{},
},
{
options: []Option{WithYear(2050), WithMonth(12)},
expected: holidays{},
},
{
options: []Option{WithYear(2050), WithDay(31)},
expected: holidays{},
},
}
for _, test := range tests {
holidays := Holidays(test.options...)
if len(test.expected) != len(holidays) {
t.Errorf("Holidays count is wrong. expected: %v, but: %v", len(test.expected), len(holidays))
}
for i := 0; i < len(test.expected); i++ {
expected := test.expected[i]
holiday := holidays[i]
if expected.Year() != holiday.Year() {
t.Errorf("Holidays[%d] Year is wrong. expected: %v, but: %v", i, expected.Year(), holiday.Year())
}
if expected.Month() != holiday.Month() {
t.Errorf("Holidays[%d] Month is wrong. expected: %v, but: %v", i, expected.Month(), holiday.Month())
}
if expected.Day() != holiday.Day() {
t.Errorf("Holidays[%d] Day is wrong. expected: %v, but: %v", i, expected.Day(), holiday.Day())
}
}
}
}
func TestHasHolidays(t *testing.T) {
tests := []struct {
options []Option
expected bool
}{
{
options: []Option{WithYear(2050)},
expected: true,
},
{
options: []Option{WithYear(2050), WithMonth(1)},
expected: true,
},
{
options: []Option{WithYear(2050), WithDay(11)},
expected: true,
},
{
options: []Option{WithTime(func() *time.Time {
loc, _ := time.LoadLocation("Asia/Tokyo")
t := time.Date(2050, 11, 23, 8, 4, 18, 0, loc)
return &t
}())},
expected: true,
},
{
options: []Option{WithYear(1)},
expected: false,
},
{
options: []Option{WithYear(2050), WithMonth(12)},
expected: false,
},
{
options: []Option{WithYear(2050), WithDay(31)},
expected: false,
},
}
for _, test := range tests {
got := HasHoliday(test.options...)
if test.expected != got {
t.Errorf("IsHoliday is wrong. expected: %v, got: %v", test.expected, got)
}
}
}