-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic_test.go
221 lines (211 loc) · 3.94 KB
/
logic_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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package simplecsv
import (
"reflect"
"testing"
)
// compareUnorderedSlices compares if 2 slices contain the same elements in any order
func compareUnorderedSlices(x, y interface{}) bool {
nx := x.([]int)
ny := y.([]int)
for _, v := range nx {
if !contains(ny, v) {
return false
}
}
for _, k := range ny {
if !contains(nx, k) {
return false
}
}
return true
}
func Test_countIndexesInSlices(t *testing.T) {
type args struct {
indexes [][]int
}
tests := []struct {
name string
args args
want map[int]int
}{
{name: "A",
want: map[int]int{1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1},
args: args{indexes: [][]int{
{2, 4, 6, 8},
{1, 3, 5, 7},
}},
},
{name: "B",
want: map[int]int{1: 2, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 3},
args: args{indexes: [][]int{
{2, 4, 6, 8},
{1, 3, 5, 7, 8},
{1, 8},
}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := countIndexesInSlices(tt.args.indexes); !reflect.DeepEqual(got, tt.want) {
t.Errorf("countIndexesInSlices() = %v, want %v", got, tt.want)
}
})
}
}
func Test_showsMoreThanTimes(t *testing.T) {
type args struct {
valuesMap map[int]int
min int
}
tests := []struct {
name string
args args
want []int
}{
{name: "ShowMoreThanTimes1",
want: []int{2, 4},
args: args{
valuesMap: map[int]int{1: 1, 2: 2, 3: 1, 4: 3},
min: 2},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := showsMoreThanTimes(tt.args.valuesMap, tt.args.min); !compareUnorderedSlices(got, tt.want) {
t.Errorf("showsMoreThanTimes() = %v, want %v", got, tt.want)
}
})
}
}
func TestOrIndex(t *testing.T) {
type args struct {
indexes [][]int
}
tests := []struct {
name string
args args
want []int
}{
{name: "OrIndex1",
want: []int{2, 4, 6, 1, 3, 5},
args: args{
indexes: [][]int{
{2, 4, 6},
{1, 3, 5},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := OrIndex(tt.args.indexes...); !compareUnorderedSlices(got, tt.want) {
t.Errorf("OrIndex() = %v, want %v", got, tt.want)
}
})
}
}
func TestAndIndex(t *testing.T) {
type args struct {
indexes [][]int
}
tests := []struct {
name string
args args
want []int
}{
{name: "OrIndex1",
want: []int{6},
args: args{
indexes: [][]int{
{2, 4, 6},
{1, 6, 5},
{1, 6, 3},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := AndIndex(tt.args.indexes...); !reflect.DeepEqual(got, tt.want) {
t.Errorf("AndIndex() = %v, want %v", got, tt.want)
}
})
}
}
func Test_contains(t *testing.T) {
type args struct {
s []int
e int
}
tests := []struct {
name string
args args
want bool
}{
{name: "Contains1",
want: true,
args: args{
s: []int{1, 2, 3, 4},
e: 4,
},
},
{name: "Contains2",
want: false,
args: args{
s: []int{1, 2, 3, 4},
e: 9,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := contains(tt.args.s, tt.args.e); got != tt.want {
t.Errorf("contains() = %v, want %v", got, tt.want)
}
})
}
}
func TestNotIndex(t *testing.T) {
type args struct {
index []int
min int
max int
}
tests := []struct {
name string
args args
want []int
}{
{name: "NotInIndex1",
want: []int{2, 4, 6},
args: args{
index: []int{1, 3, 5, 7},
min: 1,
max: 7,
},
},
{name: "NotInIndex2",
want: []int{2, 4, 6, 0},
args: args{
index: []int{1, 3, 5, 7},
min: 0,
max: 7,
},
},
{name: "NotInIndex3",
want: []int{},
args: args{
index: []int{1, 2, 3},
min: 1,
max: 3,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NotIndex(tt.args.index, tt.args.min, tt.args.max); !compareUnorderedSlices(got, tt.want) {
t.Errorf("NotIndex() = %v, want %v", got, tt.want)
}
})
}
}