-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
91 lines (87 loc) · 1.54 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
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"testing"
"time"
)
func TestMinToHourMin(t *testing.T) {
t.Parallel()
cases := map[int]string{
0: "0h 0m",
1: "0h 1m",
30: "0h 30m",
60: "1h 0m",
61: "1h 1m",
120: "2h 0m",
121: "2h 1m",
1440: "24h 0m",
1500: "25h 0m",
9999: "166h 39m",
}
for k, v := range cases {
if minToHourMin(k) != v {
t.Errorf("%d minutes should be %s", k, v)
}
}
}
func TestSortedKeys(t *testing.T) {
t.Parallel()
type tCase struct {
in map[string]int
out []string
}
cases := []tCase{
tCase{
in: map[string]int{
"a": 1,
},
out: []string{
"a",
},
},
tCase{
in: map[string]int{
"b": 1,
"a": 1,
},
out: []string{
"a",
"b",
},
},
tCase{
in: map[string]int{
"y": 1,
"b": 1,
"a": 1,
"z": 1,
},
out: []string{
"a",
"b",
"y",
"z",
},
},
}
for _, v := range cases {
for i, x := range sortedKeys(v.in) {
if x != v.out[i] {
t.Errorf("map not sorted correctly")
}
}
}
}
func TestWeekNumber(t *testing.T) {
t.Parallel()
times := map[int]time.Time{}
times[1], _ = time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")
times[2], _ = time.Parse(time.RFC3339, "2006-01-09T15:04:05Z")
times[17], _ = time.Parse(time.RFC3339, "2006-04-30T15:04:05Z")
times[22], _ = time.Parse(time.RFC3339, "2006-06-01T15:04:05Z")
times[52], _ = time.Parse(time.RFC3339, "2006-12-31T15:04:05Z")
for k, v := range times {
if weekNumber(v) != k {
t.Errorf("incorrect week number %d for time %+v", weekNumber(v), v)
}
}
}