forked from golang/build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats_test.go
117 lines (110 loc) · 2.22 KB
/
stats_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
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"math"
"testing"
"time"
"golang.org/x/build/maintner"
)
func TestNewIntervalFromCL(t *testing.T) {
var (
t0 = time.Now()
t1 = t0.Add(1 * time.Hour)
)
testCases := []struct {
cl *maintner.GerritCL
start, end int64
}{
{
cl: &maintner.GerritCL{
Created: t0,
Status: "new",
},
start: t0.Unix(),
end: math.MaxInt64,
},
{
cl: &maintner.GerritCL{
Created: t0,
Status: "merged",
Metas: []*maintner.GerritMeta{
{
Commit: &maintner.GitCommit{
Msg: "autogenerated:gerrit:merged",
CommitTime: t1,
},
},
},
},
start: t0.Unix(),
end: t1.Unix(),
},
{
cl: &maintner.GerritCL{
Created: t0,
Status: "abandoned",
Metas: []*maintner.GerritMeta{
{
Commit: &maintner.GitCommit{
Msg: "autogenerated:gerrit:abandon",
CommitTime: t1,
},
},
},
},
start: t0.Unix(),
end: t1.Unix(),
},
}
for _, tc := range testCases {
ival := newIntervalFromCL(tc.cl)
if got, want := ival.start, tc.start; got != want {
t.Errorf("start: got %d; want %d", got, want)
}
if got, want := ival.end, tc.end; got != want {
t.Errorf("end: got %d; want %d", got, want)
}
if got, want := ival.cl, tc.cl; got != want {
t.Errorf("cl: got %+v; want %+v", got, want)
}
}
}
func TestIntervalIntersection(t *testing.T) {
testCases := []struct {
interval *clInterval
t0, t1 time.Time
intersects bool
}{
{
&clInterval{start: 0, end: 5},
time.Unix(0, 0),
time.Unix(10, 0),
true,
},
{
&clInterval{start: 10, end: 20},
time.Unix(0, 0),
time.Unix(10, 0),
true,
},
{
&clInterval{start: 10, end: 20},
time.Unix(0, 0),
time.Unix(9, 0),
false,
},
{
&clInterval{start: 0, end: 5},
time.Unix(6, 0),
time.Unix(10, 0),
false,
},
}
for _, tc := range testCases {
if got, want := tc.interval.intersects(tc.t0, tc.t1), tc.intersects; got != want {
t.Errorf("(%v).intersects(%v, %v): got %v; want %v", tc.interval, tc.t0, tc.t1, got, want)
}
}
}