/
steps_test.go
111 lines (87 loc) · 2.29 KB
/
steps_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
package elapsing
import (
"strconv"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestIndexes(t *testing.T) {
assert := assert.New(t)
emptyStep := steps{}
indexes, maxLength := emptyStep.Indexes()
assert.Empty(indexes)
assert.Zero(maxLength)
step := steps{
point{},
point{},
&Elapsing{},
}
indexes, maxLength = step.Indexes()
assert.Len(indexes, 3)
assert.NotZero(maxLength)
assert.ElementsMatch([]string{"1", "2", "3"}, indexes)
expectedIndexes := make([]string, 100)
aLotOfSteps := steps{}
for i := 0; i < 100; i++ {
aLotOfSteps = append(aLotOfSteps, &point{})
expectedIndexes[i] = strconv.FormatInt(int64(i+1), 10)
}
indexes, maxLength = aLotOfSteps.Indexes()
assert.Len(indexes, 100)
assert.NotZero(maxLength)
assert.ElementsMatch(expectedIndexes, indexes)
}
func TestNames(t *testing.T) {
assert := assert.New(t)
emptyStep := steps{}
names, maxLength := emptyStep.Names()
assert.Empty(names)
assert.Zero(maxLength)
step := steps{
point{name: "A"},
point{name: "B"},
&Elapsing{name: "C"},
}
names, maxLength = step.Names()
assert.Len(names, 3)
assert.NotZero(maxLength)
assert.ElementsMatch([]string{"A", "B", ""}, names)
}
func TestLasts(t *testing.T) {
assert := assert.New(t)
emptyStep := steps{}
lasts, maxLength := emptyStep.Lasts()
assert.Empty(lasts)
assert.Zero(maxLength)
on := time.Now()
last1 := time.Now().Add(time.Second).Sub(on)
last2 := time.Now().Add(2 * time.Second).Sub(on)
step := steps{
point{name: "A", sinceLast: last1},
point{name: "B", sinceLast: last2},
&Elapsing{name: "C"},
}
lasts, maxLength = step.Lasts()
assert.Len(lasts, 3)
assert.NotZero(maxLength)
assert.ElementsMatch([]string{last1.String(), last2.String(), "0s"}, lasts)
}
func TestTotals(t *testing.T) {
assert := assert.New(t)
emptyStep := steps{}
totals, maxLength := emptyStep.Totals()
assert.Empty(totals)
assert.Zero(maxLength)
on := time.Now()
total1 := time.Now().Add(time.Second).Sub(on)
total2 := time.Now().Add(2 * time.Second).Sub(on)
step := steps{
point{name: "A", sinceInitial: total1},
point{name: "B", sinceInitial: total2},
&Elapsing{name: "C"},
}
totals, maxLength = step.Totals()
assert.Len(totals, 3)
assert.NotZero(maxLength)
assert.ElementsMatch([]string{total1.String(), total2.String(), "0s"}, totals)
}