-
Notifications
You must be signed in to change notification settings - Fork 0
/
weekday_test.go
78 lines (75 loc) · 1.94 KB
/
weekday_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
package schedule
import (
"testing"
"time"
)
func TestWeekdayRule_HappensOn(t *testing.T) {
tests := []struct {
name string
rule WeekdayRule
date time.Time
want bool
}{
{
name: "Every Monday",
rule: WeekdayRule{Day: time.Monday, Occur: Every},
date: time.Date(2023, 9, 11, 0, 0, 0, 0, time.UTC),
want: true,
},
{
name: "Last Monday of the month - true",
rule: WeekdayRule{Day: time.Monday, Occur: Last},
date: time.Date(2022, 11, 28, 0, 0, 0, 0, time.UTC),
want: true,
},
{
name: "Last Monday of the month - false",
rule: WeekdayRule{Day: time.Monday, Occur: Last},
date: time.Date(2022, 11, 21, 0, 0, 0, 0, time.UTC),
want: false,
},
{
name: "First Monday of the month - true",
rule: WeekdayRule{Day: time.Monday, Occur: First},
date: time.Date(2022, 11, 7, 0, 0, 0, 0, time.UTC),
want: true,
},
{
name: "First Monday of the month - false",
rule: WeekdayRule{Day: time.Monday, Occur: First},
date: time.Date(2022, 11, 8, 0, 0, 0, 0, time.UTC),
want: false,
},
{
name: "Second Monday of the month- true",
rule: WeekdayRule{Day: time.Monday, Occur: Second},
date: time.Date(2022, 11, 14, 0, 0, 0, 0, time.UTC),
want: true,
},
{
name: "Second Monday of the month - false",
rule: WeekdayRule{Day: time.Monday, Occur: Second},
date: time.Date(2022, 11, 15, 0, 0, 0, 0, time.UTC),
want: false,
},
{
name: "Third Monday of the month - true",
rule: WeekdayRule{Day: time.Monday, Occur: Third},
date: time.Date(2022, 11, 21, 0, 0, 0, 0, time.UTC),
want: true,
},
{
name: "Third Monday of the month - false",
rule: WeekdayRule{Day: time.Monday, Occur: Third},
date: time.Date(2022, 11, 22, 0, 0, 0, 0, time.UTC),
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.rule.HappensOn(tt.date); got != tt.want {
t.Errorf("WeekdayRule.HappensOn() = %v, want %v", got, tt.want)
}
})
}
}