/
calendar_test.go
70 lines (58 loc) · 1.68 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
package calendar_test
import (
"testing"
"time"
"github.com/saulhoward/calendar"
)
func TestAvailableRange(t *testing.T) {
bobsCal := calendar.New("Bob's holiday calendar")
eventStart := time.Date(2015, time.November, 5, 19, 0, 0, 0, time.UTC)
event := calendar.Event{
Start: eventStart,
End: eventStart.Add(2 * time.Hour),
Id: "Guy Fawkes Night",
}
bobsCal.AddEvent(event)
conflictingEventStart := time.Date(2015, time.November, 5, 20, 0, 0, 0, time.UTC)
isAvailable := calendar.AvailableRange(
conflictingEventStart,
conflictingEventStart.Add(1*time.Hour),
bobsCal,
)
if isAvailable {
t.Error("Conflicting range declared available")
}
nonconflictingEventStart := time.Date(2015, time.November, 6, 12, 0, 0, 0, time.UTC)
isAvailable = calendar.AvailableRange(
nonconflictingEventStart,
nonconflictingEventStart.Add(1*time.Hour),
bobsCal,
)
if !isAvailable {
t.Error("Non conflicting range declared unavailable")
}
}
func TestGetEvents(t *testing.T) {
bobsCal := calendar.New("Bob's holiday calendar")
eventStart := time.Date(2015, time.November, 5, 19, 0, 0, 0, time.UTC)
event := calendar.Event{
Start: eventStart,
End: eventStart.Add(2 * time.Hour),
Id: "later",
}
bobsCal.AddEvent(event)
event2Start := time.Date(2015, time.November, 4, 19, 0, 0, 0, time.UTC)
event2 := calendar.Event{
Start: event2Start,
End: event2Start.Add(2 * time.Hour),
Id: "earlier",
}
bobsCal.AddEvent(event2)
events := bobsCal.Events()
if len(events) != 2 {
t.Errorf("Wrong number of events returned. Expected 2, got %v", len(events))
}
if events[0].Id != "earlier" {
t.Errorf("Events returned in the wrong order. Got %v first", events[0])
}
}