-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar_test.go
87 lines (71 loc) · 2.16 KB
/
calendar_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
package schedule
import (
"slices"
"testing"
"time"
)
func TestListEventsBetween(t *testing.T) {
start := time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC)
end := time.Date(2023, 9, 30, 0, 0, 0, 0, time.UTC)
event1 := Event{ // happens every day
StartDate: time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
EndDate: time.Date(2023, 9, 30, 0, 0, 0, 0, time.UTC),
Frequency: Daily,
}
event2 := Event{ // happens every Sunday
StartDate: time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
EndDate: time.Date(2023, 9, 30, 0, 0, 0, 0, time.UTC),
Frequency: Weekly,
WeekdayRule: WeekdayRule{
Day: time.Sunday,
Occur: Every,
},
}
event3 := Event{ // happens on the 15th of every month
StartDate: time.Date(2023, 9, 1, 0, 0, 0, 0, time.UTC),
EndDate: time.Date(2023, 9, 30, 0, 0, 0, 0, time.UTC),
Frequency: Monthly,
DayOfMonth: 15,
}
event4 := Event{ // happens on the 15th of September every year
StartDate: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
EndDate: time.Date(2025, 10, 30, 0, 0, 0, 0, time.UTC),
Frequency: Yearly,
Month: 9,
DayOfMonth: 15,
}
event5 := Event{ // one-time event
Date: time.Date(2023, 9, 15, 0, 0, 0, 0, time.UTC),
}
event6 := Event{ // happens on the first monday the month
StartDate: time.Date(2023, 7, 1, 0, 0, 0, 0, time.UTC),
EndDate: time.Date(2023, 7, 31, 0, 0, 0, 0, time.UTC),
Frequency: Weekly,
WeekdayRule: WeekdayRule{
Day: time.Monday,
Occur: First,
},
}
calendar := Calendar{
Events: []Event{event1, event2, event3, event4, event5, event6},
}
filteredEvents := calendar.ListEventsBetween(start, end)
if !slices.Contains(filteredEvents, event1) {
t.Error("Event1 should be in the list")
}
if !slices.Contains(filteredEvents, event2) {
t.Error("Event2 should be in the list")
}
if !slices.Contains(filteredEvents, event3) {
t.Error("Event3 should be in the list")
}
if !slices.Contains(filteredEvents, event4) {
t.Error("Event4 should be in the list")
}
if !slices.Contains(filteredEvents, event5) {
t.Error("Event5 should be in the list")
}
if len(filteredEvents) != 5 {
t.Errorf("There should be 3 events in the list, got %d", len(filteredEvents))
}
}