-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinterval_test.go
120 lines (94 loc) · 3.45 KB
/
interval_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
package bitesized
import (
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
var randomTime = time.Date(1981, time.June, 12, 01, 42, 0, 0, time.UTC)
func TestNearestInterval(t *testing.T) {
Convey("It should empty for 'All'", t, func() {
n := nearestInterval(randomTime, All)
So(n, ShouldEqual, "all")
})
Convey("It should find nearest hour", t, func() {
n := nearestInterval(randomTime, Hour)
So(n, ShouldEqual, "hour:1981-06-12-01:00")
})
Convey("It should find nearest day", t, func() {
n := nearestInterval(randomTime, Day)
So(n, ShouldEqual, "day:1981-06-12")
})
Convey("It should find nearest week", t, func() {
n := nearestInterval(randomTime, Week)
So(n, ShouldEqual, "week:1981-06-07")
})
Convey("It should find nearest month", t, func() {
n := nearestInterval(randomTime, Month)
So(n, ShouldEqual, "month:1981-06")
})
Convey("It should find nearest year", t, func() {
n := nearestInterval(randomTime, Year)
So(n, ShouldEqual, "year:1981")
})
Convey("It should find nearest quarter", t, func() {
n := nearestInterval(randomTime, Quarter)
So(n, ShouldEqual, "quarter:1981-04")
})
Convey("It should find nearest 10 minute cycle", t, func() {
n := nearestInterval(randomTime, TenMinutes)
So(n, ShouldEqual, "ten_minutes:1981-06-12-01:40")
})
Convey("It should find nearest 30 minute cycle", t, func() {
n := nearestInterval(randomTime, ThirtyMinutes)
So(n, ShouldEqual, "thirty_minutes:1981-06-12-01:30")
})
Convey("It should find nearest biweekly date (first part)", t, func() {
testingTime := time.Date(1981, time.June, 12, 01, 42, 0, 0, time.UTC)
n := nearestInterval(testingTime, Biweekly)
So(n, ShouldEqual, "biweekly:1981-06-10")
})
Convey("It should find nearest biweekly date (second part)", t, func() {
testingTime := time.Date(1981, time.June, 16, 01, 42, 0, 0, time.UTC)
n := nearestInterval(testingTime, Biweekly)
So(n, ShouldEqual, "biweekly:1981-06-14")
})
Convey("It should find nearest bimonthly date (first part)", t, func() {
testingTime := time.Date(1981, time.June, 12, 01, 42, 0, 0, time.UTC)
n := nearestInterval(testingTime, Bimonthly)
So(n, ShouldEqual, "bimonthly:1981-06-01")
})
Convey("It should find nearest bimonthly date (second part)", t, func() {
testingTime := time.Date(1981, time.June, 28, 01, 42, 0, 0, time.UTC)
n := nearestInterval(testingTime, Bimonthly)
So(n, ShouldEqual, "bimonthly:1981-06-15")
})
}
func TestGetDuration(t *testing.T) {
Convey("It should return duration for hour", t, func() {
d := getDuration(randomTime, Hour)
So(d, ShouldEqual, 1*time.Hour)
})
Convey("It should return duration for day", t, func() {
d := getDuration(randomTime, Day)
So(d, ShouldEqual, 24*time.Hour)
})
Convey("It should return duration for week", t, func() {
d := getDuration(randomTime, Week)
So(d, ShouldEqual, 7*24*time.Hour)
})
Convey("It should return duration for month with 31 days", t, func() {
t := time.Date(2015, time.January, 01, 00, 0, 0, 0, time.UTC)
d := getDuration(t, Month)
So(d, ShouldEqual, 31*24*time.Hour)
})
Convey("It should return duration for month with 30 days", t, func() {
t := time.Date(2015, time.April, 01, 00, 0, 0, 0, time.UTC)
d := getDuration(t, Month)
So(d, ShouldEqual, 30*24*time.Hour)
})
Convey("It should return duration for month with 28 days", t, func() {
t := time.Date(2015, time.February, 01, 00, 0, 0, 0, time.UTC)
d := getDuration(t, Month)
So(d, ShouldEqual, 28*24*time.Hour)
})
}