@@ -12,22 +12,23 @@ import (
12
12
"tailscale.com/util/uniq"
13
13
)
14
14
15
- func runTests (t * testing.T , cb func (* []int )) {
15
+ func runTests (t * testing.T , cb func (* []uint32 )) {
16
16
tests := []struct {
17
- in []int
18
- want []int
17
+ // Use uint32 to be different from an int-typed slice index
18
+ in []uint32
19
+ want []uint32
19
20
}{
20
- {in : []int {0 , 1 , 2 }, want : []int {0 , 1 , 2 }},
21
- {in : []int {0 , 1 , 2 , 2 }, want : []int {0 , 1 , 2 }},
22
- {in : []int {0 , 0 , 1 , 2 }, want : []int {0 , 1 , 2 }},
23
- {in : []int {0 , 1 , 0 , 2 }, want : []int {0 , 1 , 0 , 2 }},
24
- {in : []int {0 }, want : []int {0 }},
25
- {in : []int {0 , 0 }, want : []int {0 }},
26
- {in : []int {}, want : []int {}},
21
+ {in : []uint32 {0 , 1 , 2 }, want : []uint32 {0 , 1 , 2 }},
22
+ {in : []uint32 {0 , 1 , 2 , 2 }, want : []uint32 {0 , 1 , 2 }},
23
+ {in : []uint32 {0 , 0 , 1 , 2 }, want : []uint32 {0 , 1 , 2 }},
24
+ {in : []uint32 {0 , 1 , 0 , 2 }, want : []uint32 {0 , 1 , 0 , 2 }},
25
+ {in : []uint32 {0 }, want : []uint32 {0 }},
26
+ {in : []uint32 {0 , 0 }, want : []uint32 {0 }},
27
+ {in : []uint32 {}, want : []uint32 {}},
27
28
}
28
29
29
30
for _ , test := range tests {
30
- in := make ([]int , len (test .in ))
31
+ in := make ([]uint32 , len (test .in ))
31
32
copy (in , test .in )
32
33
cb (& test .in )
33
34
if ! reflect .DeepEqual (test .in , test .want ) {
@@ -44,11 +45,19 @@ func runTests(t *testing.T, cb func(*[]int)) {
44
45
}
45
46
46
47
func TestModifySlice (t * testing.T ) {
47
- runTests (t , func (slice * []int ) {
48
+ runTests (t , func (slice * []uint32 ) {
48
49
uniq .ModifySlice (slice )
49
50
})
50
51
}
51
52
53
+ func TestModifySliceFunc (t * testing.T ) {
54
+ runTests (t , func (slice * []uint32 ) {
55
+ uniq .ModifySliceFunc (slice , func (i , j uint32 ) bool {
56
+ return i == j
57
+ })
58
+ })
59
+ }
60
+
52
61
func Benchmark (b * testing.B ) {
53
62
benches := []struct {
54
63
name string
0 commit comments