-
Notifications
You must be signed in to change notification settings - Fork 0
/
ermux_test.go
181 lines (171 loc) · 3.33 KB
/
ermux_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
package ermux
import (
"errors"
"testing"
)
var master = []error{
errors.New("error 1"),
errors.New("error 2"),
errors.New("error 3"),
}
type Truth struct {
first error
last error
some bool
filter []error
}
type Dataset struct {
errors []error
truth Truth
}
var tests = map[string]Dataset{
"dataset 01": {
errors: []error{nil, nil, nil},
truth: Truth{
first: nil,
last: nil,
some: false,
filter: []error{},
},
},
"dataset 02": {
errors: []error{master[0], nil, nil},
truth: Truth{
first: master[0],
last: master[0],
some: true,
filter: []error{master[0]},
},
},
"dataset 03": {
errors: []error{nil, master[1], nil},
truth: Truth{
first: master[1],
last: master[1],
some: true,
filter: []error{master[1]},
},
},
"dataset 04": {
errors: []error{master[0], master[1], nil},
truth: Truth{
first: master[0],
last: master[1],
some: true,
filter: []error{master[0], master[1]},
},
},
"dataset 05": {
errors: []error{nil, nil, master[2]},
truth: Truth{
first: master[2],
last: master[2],
some: true,
filter: []error{master[2]},
},
},
"dataset 06": {
errors: []error{master[0], nil, master[2]},
truth: Truth{
first: master[0],
last: master[2],
some: true,
filter: []error{master[0], master[2]},
},
},
"dataset 07": {
errors: []error{nil, master[1], master[2]},
truth: Truth{
first: master[1],
last: master[2],
some: true,
filter: []error{master[1], master[2]},
},
},
"dataset 08": {
errors: []error{master[0], master[1], master[2]},
truth: Truth{
first: master[0],
last: master[2],
some: true,
filter: []error{master[0], master[1], master[2]},
},
},
"dataset 09": {
errors: []error{},
truth: Truth{
first: nil,
last: nil,
some: false,
filter: []error{},
},
},
"dataset 10": {
errors: []error{nil, master[0], nil, master[1], nil, master[2], nil},
truth: Truth{
first: master[0],
last: master[2],
some: true,
filter: []error{master[0], master[1], master[2]},
},
},
}
func TestFirst(test *testing.T) {
for name, data := range tests {
test.Run(name, func(t *testing.T) {
res := First(data.errors)
if res != data.truth.first {
t.Logf("res: %v", res)
t.Logf("truth: %v", data.truth.first)
t.Error(name)
}
})
}
}
func TestLast(test *testing.T) {
for name, data := range tests {
test.Run(name, func(t *testing.T) {
res := Last(data.errors)
if res != data.truth.last {
t.Logf("res: %v", res)
t.Logf("truth: %v", data.truth.last)
t.Error(name)
}
})
}
}
func TestSome(test *testing.T) {
for name, data := range tests {
test.Run(name, func(t *testing.T) {
res := Some(data.errors)
if res != data.truth.some {
t.Logf("res: %v", res)
t.Logf("truth: %v", data.truth.some)
t.Error(name)
}
})
}
}
func TestFilter(test *testing.T) {
for name, data := range tests {
test.Run(name, func(t *testing.T) {
res := Filter(data.errors)
if !isEqual(res, data.truth.filter) {
t.Logf("res: %v", res)
t.Logf("truth: %v", data.truth.filter)
t.Error(name)
}
})
}
}
func isEqual(errs1 []error, errs2 []error) bool {
if len(errs1) != len(errs2) {
return false
}
for i := 0; i < len(errs1); i++ {
if errs1[i] != errs2[i] {
return false
}
}
return true
}