-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorderedset_test.go
129 lines (125 loc) · 2.71 KB
/
orderedset_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
package sets
import (
"cmp"
"reflect"
"testing"
)
func TestNewOrderedSet(t *testing.T) {
type args[T cmp.Ordered] struct {
items []T
}
type testCase[T cmp.Ordered] struct {
name string
args args[T]
want map[T]struct{}
}
tests := []testCase[string]{
{
name: "empty",
args: struct{ items []string }{items: nil},
want: map[string]struct{}{},
},
{
name: "one",
args: struct{ items []string }{items: []string{"two"}},
want: map[string]struct{}{"two": struct{}{}},
},
{
name: "two",
args: struct{ items []string }{items: []string{"one", "two"}},
want: map[string]struct{}{"one": struct{}{}, "two": struct{}{}},
},
{
name: "three",
args: struct{ items []string }{items: []string{"one", "two", "three"}},
want: map[string]struct{}{"one": struct{}{}, "two": struct{}{}, "three": struct{}{}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NewOrderedSet(tt.args.items...); !reflect.DeepEqual(got.innerMap, tt.want) {
t.Errorf("NewOrderedSet() = %v, wantAfterSort %v", got, tt.want)
}
})
}
}
func TestOrderdSet_Contains(t *testing.T) {
type args[T cmp.Ordered] struct {
t T
}
type testCase[T cmp.Ordered] struct {
name string
s *OrderdSet[T]
args args[T]
wantFound bool
}
tests := []testCase[string]{
{
name: "empty-contains",
s: NewOrderedSet[string](),
args: args[string]{
t: "x",
},
wantFound: false,
},
{
name: "three-does-contain",
s: NewOrderedSet("one", "two", "three"),
args: args[string]{
t: "one",
},
wantFound: true,
},
{
name: "three-does-not-contain",
s: NewOrderedSet("one", "two", "three"),
args: args[string]{
t: "four",
},
wantFound: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotFound := tt.s.Contains(tt.args.t); gotFound != tt.wantFound {
t.Errorf("Contains() = %v, wantAfterSort %v", gotFound, tt.wantFound)
}
})
}
}
func TestOrderdSet_Values(t *testing.T) {
type testCase[T cmp.Ordered] struct {
name string
s *OrderdSet[T]
want []T
}
tests := []testCase[string]{
{
name: "empty",
s: NewOrderedSet[string](),
want: []string{},
},
{
name: "one",
s: NewOrderedSet("alpha"),
want: []string{"alpha"},
},
{
name: "two",
s: NewOrderedSet("alpha", "beta"),
want: []string{"alpha", "beta"},
},
{
name: "three",
s: NewOrderedSet("alpha", "beta", "gamma"),
want: []string{"alpha", "beta", "gamma"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.Values(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Values() = %v, wantAfterSort %v", got, tt.want)
}
})
}
}