-
Notifications
You must be signed in to change notification settings - Fork 1
/
timeslot_test.go
67 lines (58 loc) · 1.47 KB
/
timeslot_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
package myradio_test
import (
"reflect"
"testing"
"time"
myradio "github.com/UniversityRadioYork/myradio-go"
)
// TestCanEntryZero tests whether a zero-valued CurrentAndNext entry returns true for IsZero.
// It does NOT (yet) test the converse.
func TestCanEntryZero(t *testing.T) {
s := myradio.Show{}
if !s.StartTime.IsZero() || !s.EndTime.IsZero() {
t.Error("zero show returns false for IsZero")
}
}
// TestCanEntryEnds tests whether a CurrentAndNext entry returns something sensible for Ends.
func TestCanEntryEnds(t *testing.T) {
cases := []struct {
t myradio.Time
e bool
}{
{t: myradio.Time{}, e: false},
{t: myradio.Time{time.Date(2009, time.April, 13, 11, 11, 11, 0, time.UTC)}, e: true},
}
for _, c := range cases {
s := myradio.Show{}
s.EndTime = c.t
if s.Ends() != c.e {
t.Error("show with end time", c.t, "gave incorrect Ends() of", s.Ends())
}
}
}
// TestGetWeekScheduleZero tests whether GetWeekSchedule handles empty schedules correctly.
func TestGetWeekScheduleZero(t *testing.T) {
expected := map[int][]myradio.Timeslot{
1: {},
2: {},
3: {},
4: {},
5: {},
6: {},
7: {},
}
zeroes := [][]byte{[]byte("[]"), []byte("{}")}
for _, zero := range zeroes {
session, err := myradio.MockSession(zero)
if err != nil {
t.Error(err)
}
schedule, err := session.GetWeekSchedule(0, 1)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(schedule, expected) {
t.Error("expected:", expected, "got:", schedule)
}
}
}