-
Notifications
You must be signed in to change notification settings - Fork 0
/
konfurbot_test.go
127 lines (102 loc) · 3.73 KB
/
konfurbot_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
package konfurbot
import (
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func TestSchedule(t *testing.T) {
Convey("Мы наполняем расписание событиями", t, func() {
start := time.Now().Add(-30 * time.Minute)
finish := time.Now().Add(30 * time.Minute)
schedule := Schedule{}
food0 := Event{
Type: "food",
Short: "Кофе-брейк",
Long: "",
Start: &start,
Finish: &finish,
}
schedule.AddEvent(food0)
food1 := Event{
Type: "food",
Short: "Ужин",
Long: "",
Start: &start,
Finish: &finish,
}
schedule.AddEvent(food1)
talk0 := Event{
Type: "talk",
Short: "WAT",
Long: "В докладе пойдет речь о том,\nчему равна сумма объекта и пустой строки.\n",
Start: &start,
Finish: &finish,
}
schedule.AddEvent(talk0)
nightCutoff, _ := time.Parse("02.01.2006 15:04", "26.11.2016 20:00")
schedule.SetNightCutoff(nightCutoff)
fun0 := Event{
Type: "fun",
Short: "Боулинг на весь день",
}
schedule.AddEvent(fun0)
startFixed, _ := time.Parse("02.01.2006 15:04", "26.11.2016 10:00")
finishFixed, _ := time.Parse("02.01.2006 15:04", "26.11.2016 17:00")
fun1 := Event{
Type: "fun",
Short: "Клавогонки днем",
Start: &startFixed,
Finish: &finishFixed,
}
schedule.AddEvent(fun1)
startFixed2, _ := time.Parse("02.01.2006 15:04", "26.11.2016 20:00")
finishFixed2, _ := time.Parse("02.01.2006 15:04", "26.11.2016 23:00")
fun2 := Event{
Type: "fun",
Short: "ЧГК вечером",
Start: &startFixed2,
Finish: &finishFixed2,
}
schedule.AddEvent(fun2)
Convey("а потом получаем все события определенного типа в том же порядке", func() {
foodEvents := schedule.GetEventsByType("food")
So(foodEvents, ShouldHaveLength, 2)
So(foodEvents[0], ShouldResemble, food0)
So(foodEvents[1], ShouldResemble, food1)
})
Convey("а потом получаем текущие события определенного типа", func() {
Convey("если они есть", func() {
talkEvents := schedule.GetCurrentEventsByType("talk", time.Now())
So(talkEvents, ShouldHaveLength, 1)
So(talkEvents[0], ShouldResemble, talk0)
})
Convey("если их нет", func() {
talkEvents := schedule.GetCurrentEventsByType("talk", time.Now().Add(time.Hour))
So(talkEvents, ShouldHaveLength, 0)
})
})
Convey("а потом получаем ближайшие события определенного типа", func() {
Convey("если они есть", func() {
talkEvents := schedule.GetNextEventsByType("talk", time.Now().Add(-time.Hour), time.Hour)
So(talkEvents, ShouldHaveLength, 1)
So(talkEvents[0], ShouldResemble, talk0)
})
Convey("если их нет", func() {
talkEvents := schedule.GetNextEventsByType("talk", time.Now(), time.Hour)
So(talkEvents, ShouldHaveLength, 0)
})
})
Convey("а потом получаем события, которые начинаются раньше определенного времени", func() {
funDayEvents := schedule.GetDayEventsByType("fun")
So(funDayEvents, ShouldHaveLength, 2)
So(funDayEvents[0], ShouldResemble, fun0)
So(funDayEvents[1], ShouldResemble, fun1)
})
Convey("а потом получаем события, которые заканчиваются позже определенного времени", func() {
funNightEvents := schedule.GetNightEventsByType("fun")
So(funNightEvents, ShouldHaveLength, 2)
So(funNightEvents[0], ShouldResemble, fun0)
So(funNightEvents[1], ShouldResemble, fun2)
})
})
}