-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil_test.go
More file actions
77 lines (73 loc) · 1.31 KB
/
util_test.go
File metadata and controls
77 lines (73 loc) · 1.31 KB
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
package main
import (
"reflect"
"testing"
)
func TestSortPages(t *testing.T) {
tests := []struct {
name string
input map[string]int
expected []reportPage
}{
{
name: "order count descending",
input: map[string]int{
"url1": 5,
"url2": 1,
"url3": 3,
"url4": 10,
"url5": 7,
},
expected: []reportPage{
{url: "url4", count: 10},
{url: "url5", count: 7},
{url: "url1", count: 5},
{url: "url3", count: 3},
{url: "url2", count: 1},
},
},
{
name: "alphabetize",
input: map[string]int{
"d": 1,
"a": 1,
"e": 1,
"b": 1,
"c": 1,
},
expected: []reportPage{
{url: "a", count: 1},
{url: "b", count: 1},
{url: "c", count: 1},
{url: "d", count: 1},
{url: "e", count: 1},
},
},
{
name: "empty map",
input: map[string]int{},
expected: []reportPage{},
},
{
name: "nil map",
input: nil,
expected: []reportPage{},
},
{
name: "one key",
input: map[string]int{
"url1": 1,
},
expected: []reportPage{
{url: "url1", count: 1},
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if actual := sortPages(tc.input); !reflect.DeepEqual(actual, tc.expected) {
t.Errorf("sortPages() = %v, expected %v", actual, tc.expected)
}
})
}
}