-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeRange_test.go
65 lines (50 loc) · 1.37 KB
/
TimeRange_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
package logparser
import (
"testing"
"time"
)
func TestTimeRange_Includes(t *testing.T) {
data := []struct {
startOffset, endOffset int
otherTimeOffset int
want bool
}{
{ 0, 5, 7, false},
{ 0, 5, 3, true},
{ 0, 5, -3, false},
}
for _, test := range data {
tr := TimeRange{
time.Now().Add( time.Duration(test.startOffset) * time.Minute),
time.Now().Add( time.Duration(test.endOffset) * time.Minute) ,
}
otherTime := time.Now().Add(time.Duration(test.otherTimeOffset) * time.Minute)
if tr.Includes(otherTime) != test.want {
t.Fatalf("TimeRange %v include test resulted in %v with argument %v", tr, test.want, otherTime)
}
}
}
func TestTimeRange_Intersects(t *testing.T) {
data := []struct {
startOffset, endOffset int
otherStarOffset, otherEndOffset int
want bool
}{
{ 0, 5, 6, 7, false},
{ 0, 5, 3, 7, true},
{ 0, 5, -3, -1, false},
}
for _, test := range data {
tr := TimeRange{
time.Now().Add( time.Duration(test.startOffset) * time.Minute),
time.Now().Add( time.Duration(test.endOffset) * time.Minute) ,
}
other := TimeRange{
time.Now().Add( time.Duration(test.otherStarOffset) * time.Minute),
time.Now().Add( time.Duration(test.otherEndOffset) * time.Minute) ,
}
if tr.Intersects(other) != test.want {
t.Fatalf("TimeRange %v include test resulted in %v with argument %v", tr, test.want, other)
}
}
}