-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil_test.go
79 lines (76 loc) · 1.21 KB
/
util_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
package xgp
import (
"fmt"
"testing"
"time"
)
func TestCountDistinct(t *testing.T) {
var (
testCases = []struct {
x []float64
n int
}{
{
x: []float64{1, 2, 3},
n: 3,
},
{
x: []float64{1, 1, 3},
n: 2,
},
{
x: []float64{1, 1, 1},
n: 1,
},
{
x: []float64{},
n: 0,
},
}
)
for i, tc := range testCases {
t.Run(fmt.Sprintf("TC %d", i), func(t *testing.T) {
var n = countDistinct(tc.x)
if n != tc.n {
t.Errorf("Expected %d, got %d", tc.n, n)
}
})
}
}
func TestFmtDuration(t *testing.T) {
var (
testCases = []struct {
d time.Duration
s string
}{
{
d: time.Duration(42) * time.Second,
s: "00:00:42",
},
{
d: time.Duration(42+60*42) * time.Second,
s: "00:42:42",
},
{
d: time.Duration(42+60*42+42*60*60) * time.Second,
s: "42:42:42",
},
{
d: time.Duration(42) * time.Nanosecond,
s: "00:00:00",
},
{
d: time.Duration(42+60*42+42*60*60*60) * time.Second,
s: "2520:42:42",
},
}
)
for i, tc := range testCases {
t.Run(fmt.Sprintf("TC %d", i), func(t *testing.T) {
var s = fmtDuration(tc.d)
if s != tc.s {
t.Errorf("Expected %s, got %s", tc.s, s)
}
})
}
}