-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup_test.go
198 lines (156 loc) · 3.99 KB
/
group_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package retrosort
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func getTestGroup() group {
return newGroup([]string{
"/some/path/first",
"/another/path/2nd.file",
"/does/not/matter/and a third",
"/somewhere/a 4th file",
})
}
func TestGroupPrefixZero(t *testing.T) {
g := getTestGroup()
if g.Len() != 4 {
t.Error("Length isn't 4")
}
if g.name() != "" {
t.Error("Name isn't blank")
}
if d := cmp.Diff(": 4", g.String()); d != "" {
t.Error(d)
}
if d := cmp.Diff(map[string]string{
"/some/path/first": "first",
"/another/path/2nd.file": "2nd.file",
"/does/not/matter/and a third": "and a third",
"/somewhere/a 4th file": "a 4th file",
}, g.fileMap()); d != "" {
t.Error(d)
}
}
func TestGroupPrefixOne(t *testing.T) {
g := getTestGroup()
g.prefixSize = 1
if g.Len() != 4 {
t.Error("Length is incorrect")
}
if g.name() != "#-f" {
t.Error("Name is incorrect")
}
if d := cmp.Diff("#-f: 4", g.String()); d != "" {
t.Error(d)
}
if d := cmp.Diff(map[string]string{
"/some/path/first": "#-f/first",
"/another/path/2nd.file": "#-f/2nd.file",
"/does/not/matter/and a third": "#-f/and a third",
"/somewhere/a 4th file": "#-f/a 4th file",
}, g.fileMap()); d != "" {
t.Error(d)
}
}
func TestGroupPrefixTwo(t *testing.T) {
g := getTestGroup()
g.prefixSize = 2
if g.Len() != 4 {
t.Error("Length is incorrect")
}
if g.name() != "2n-fi" {
t.Error("Name is incorrect")
}
if d := cmp.Diff("2n-fi: 4", g.String()); d != "" {
t.Error(d)
}
if d := cmp.Diff(map[string]string{
"/some/path/first": "2n-fi/first",
"/another/path/2nd.file": "2n-fi/2nd.file",
"/does/not/matter/and a third": "2n-fi/and a third",
"/somewhere/a 4th file": "2n-fi/a 4th file",
}, g.fileMap()); d != "" {
t.Error(d)
}
}
func TestGroupSortNone(t *testing.T) {
g := getTestGroup()
groups := g.sort(100)
if len(groups) != 1 {
t.Error("Should be just one group")
}
g = groups[0]
if g.prefixSize != 0 {
t.Errorf("Should be a 0 prefix, got %d", g.prefixSize)
}
if d := cmp.Diff(map[string]string{
"/some/path/first": "first",
"/another/path/2nd.file": "2nd.file",
"/does/not/matter/and a third": "and a third",
"/somewhere/a 4th file": "a 4th file",
}, g.fileMap()); d != "" {
t.Error(d)
}
}
func TestGroupSortBasic(t *testing.T) {
g := getTestGroup()
groups := g.sort(2)
if len(groups) != 3 {
t.Errorf("Expected 3 groups, got %d", len(groups))
}
if d := cmp.Diff(map[string]string{
"/another/path/2nd.file": "#/2nd.file",
}, groups[0].fileMap()); d != "" {
t.Error(d)
}
if d := cmp.Diff(map[string]string{
"/does/not/matter/and a third": "a-f/a/and a third",
"/somewhere/a 4th file": "a-f/a/a 4th file",
}, groups[1].fileMap()); d != "" {
t.Error(d)
}
if d := cmp.Diff(map[string]string{
"/some/path/first": "a-f/f/first",
}, groups[2].fileMap()); d != "" {
t.Error(d)
}
}
func TestGroupSortRecurse(t *testing.T) {
g := getTestGroup()
groups := g.sort(1)
if len(groups) != 4 {
t.Errorf("Expected 4 groups, got %d", len(groups))
}
if d := cmp.Diff(map[string]string{
"/another/path/2nd.file": "#/2nd.file",
}, groups[0].fileMap()); d != "" {
t.Error(d)
}
if d := cmp.Diff(map[string]string{
"/somewhere/a 4th file": "a/a_/a 4th file",
}, groups[1].fileMap()); d != "" {
t.Error(d)
}
if d := cmp.Diff(map[string]string{
"/does/not/matter/and a third": "a/an/and a third",
}, groups[2].fileMap()); d != "" {
t.Error(d)
}
if d := cmp.Diff(map[string]string{
"/some/path/first": "f/first",
}, groups[3].fileMap()); d != "" {
t.Error(d)
}
}
func TestGroups(t *testing.T) {
g := getTestGroup()
groups := g.sort(2)
if d := cmp.Diff(map[string]string{
"/another/path/2nd.file": "#/2nd.file",
"/somewhere/a 4th file": "a-f/a/a 4th file",
"/does/not/matter/and a third": "a-f/a/and a third",
"/some/path/first": "a-f/f/first",
}, groups.fileMap()); d != "" {
t.Error(d)
}
}