forked from mpvl/unique
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunique_test.go
55 lines (52 loc) · 998 Bytes
/
unique_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
package unique
import (
"reflect"
"testing"
)
func TestUnique(t *testing.T) {
for i, tc := range []struct {
data, want Interface
}{
{
IntSlice{&[]int{}},
IntSlice{&[]int{}},
},
{
IntSlice{&[]int{1}},
IntSlice{&[]int{1}},
},
{
IntSlice{&[]int{1, 2}},
IntSlice{&[]int{1, 2}},
},
{
IntSlice{&[]int{1, 1}},
IntSlice{&[]int{1}},
},
{
IntSlice{&[]int{1, 2, 2}},
IntSlice{&[]int{1, 2}},
},
{
IntSlice{&[]int{1, 1, 2}},
IntSlice{&[]int{1, 2}},
},
{
GenericSlice[uint]{&[]uint{1, 1, 2, 3, 3}},
GenericSlice[uint]{&[]uint{1, 2, 3}},
},
} {
Unique(tc.data)
if !reflect.DeepEqual(tc.data, tc.want) {
t.Errorf("%d: got %#v; want %#v", i, tc.data, tc.want)
}
}
}
func TestGenericsAreUnique(t *testing.T) {
have := GenericSlice[int8]{&[]int8{5, 4, 1, 1, -1, 2, 3, 3}}
want := GenericSlice[int8]{&[]int8{-1, 1, 2, 3, 4, 5}}
Sort(have)
if !reflect.DeepEqual(have, want) {
t.Errorf("got %#v; want %#v", want, want)
}
}