-
Notifications
You must be signed in to change notification settings - Fork 14
/
intervals_test.go
92 lines (88 loc) · 2.37 KB
/
intervals_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
package metha
import (
"testing"
"time"
)
func TimeMustParse(layout, s string) time.Time {
t, err := time.Parse(layout, s)
if err != nil {
panic(err)
}
return t
}
func TestDailyIntervals(t *testing.T) {
var cases = []struct {
Interval Interval
Result []Interval
}{
{
Interval: Interval{
Begin: TimeMustParse("2006-01-02", "2016-01-01"),
End: TimeMustParse("2006-01-02", "2016-01-03"),
},
Result: []Interval{
Interval{
TimeMustParse("2006-01-01 15:04:05", "2016-01-01 00:00:00"),
TimeMustParse("2006-01-01T15:04:05.999999999", "2016-01-01T23:59:59.999999999"),
},
Interval{
TimeMustParse("2006-01-02 15:04:05", "2016-01-02 00:00:00"),
TimeMustParse("2006-01-02T15:04:05.999999999", "2016-01-02T23:59:59.999999999"),
},
Interval{
TimeMustParse("2006-01-02 15:04:05", "2016-01-03 00:00:00"),
TimeMustParse("2006-01-02T15:04:05.999999999", "2016-01-03T23:59:59.999999999"),
},
},
},
}
for _, c := range cases {
r := c.Interval.DailyIntervals()
if len(r) != len(c.Result) {
t.Errorf("got %v, want %v", len(r), len(c.Result))
}
for i := range r {
if r[i].String() != c.Result[i].String() {
t.Errorf("got %v, want %s", r[i].String(), c.Result[i].String())
}
}
}
}
func TestHourlyIntervals(t *testing.T) {
var cases = []struct {
Interval Interval
Result []Interval
}{
{
Interval: Interval{
Begin: TimeMustParse("2006-01-02 15:04:05", "2016-01-02 17:00:00"),
End: TimeMustParse("2006-01-02 15:04:05", "2016-01-02 19:00:00"),
},
Result: []Interval{
Interval{
TimeMustParse("2006-01-02 15:04:05", "2016-01-02 17:00:00"),
TimeMustParse("2006-01-02T15:04:05.999999999", "2016-01-02T17:59:59.999999999"),
},
Interval{
TimeMustParse("2006-01-02 15:04:05", "2016-01-02 18:00:00"),
TimeMustParse("2006-01-02T15:04:05.999999999", "2016-01-02T18:59:59.999999999"),
},
Interval{
TimeMustParse("2006-01-02 15:04:05", "2016-01-02 19:00:00"),
TimeMustParse("2006-01-02T15:04:05.999999999", "2016-01-02T19:59:59.999999999"),
},
},
},
}
for _, c := range cases {
r := c.Interval.HourlyIntervals()
if len(r) != len(c.Result) {
t.Errorf("got %v, want %v", len(r), len(c.Result))
}
for i := range r {
if r[i].String() != c.Result[i].String() {
t.Errorf("got %v, want %s", r[i].String(), c.Result[i].String())
}
}
}
}