-
Notifications
You must be signed in to change notification settings - Fork 3
/
examples_test.go
60 lines (49 loc) · 1.37 KB
/
examples_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
package trn
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestMergeRanges(t *testing.T) {
now := time.Now()
rng := New(now, time.Hour+3*time.Minute)
ranges, err := rng.Stratify(15*time.Minute, 5*time.Minute)
assert.NoError(t, err)
assert.Equal(t, []Range{
New(now, 15*time.Minute),
New(now.Add(5*time.Minute), 15*time.Minute),
New(now.Add(10*time.Minute), 15*time.Minute),
New(now.Add(15*time.Minute), 15*time.Minute),
New(now.Add(20*time.Minute), 15*time.Minute),
New(now.Add(25*time.Minute), 15*time.Minute),
New(now.Add(30*time.Minute), 15*time.Minute),
New(now.Add(35*time.Minute), 15*time.Minute),
New(now.Add(40*time.Minute), 15*time.Minute),
New(now.Add(45*time.Minute), 15*time.Minute),
}, ranges)
}
func TestTruncate(t *testing.T) {
now := time.Now()
rng := New(now, time.Hour)
truncateRange := New(now.Add(15*time.Minute), time.Hour)
assert.Equal(t,
New(now.Add(15*time.Minute), 45*time.Minute),
rng.Truncate(truncateRange),
)
}
func TestFlip(t *testing.T) {
now := time.Now()
flipRange := New(now, time.Hour)
rngs := []Range{
New(now.Add(25*time.Minute), 15*time.Minute),
New(now.Add(50*time.Minute), 5*time.Minute),
}
assert.Equal(t,
[]Range{
New(now, 25*time.Minute),
New(now.Add(40*time.Minute), 10*time.Minute),
New(now.Add(55*time.Minute), 5*time.Minute),
},
flipRange.Flip(rngs),
)
}