@@ -199,6 +199,45 @@ func BenchmarkContainsLong50000(b *testing.B) {
199
199
}
200
200
}
201
201
202
+ func TestNotContains (t * testing.T ) {
203
+ cases := []testCase {
204
+ testCase {args : []interface {}{[]interface {}{"a" , "b" }, "a" }, expected : false },
205
+ testCase {args : []interface {}{[]interface {}{"a" , "b" }, "c" }, expected : true },
206
+ testCase {args : []interface {}{[]interface {}{"a" , "b" }, float64 (1 )}, expected : true },
207
+ testCase {args : []interface {}{[]interface {}{float64 (1 ), float64 (2 )}, float64 (1 )}, expected : false },
208
+ testCase {args : []interface {}{[]interface {}{float64 (1 ), float64 (2 )}, float64 (3 )}, expected : true },
209
+ testCase {args : []interface {}{[]interface {}{float64 (1.01 ), float64 (1.02 )}, float64 (1.01 )}, expected : false },
210
+ }
211
+
212
+ for i , c := range cases {
213
+ res := notContains (c .args [0 ], c .args [1 ])
214
+ if res != c .expected {
215
+ t .Fatalf ("expected case %d to be %v, got %v" , i , c .expected , res )
216
+ }
217
+ }
218
+ }
219
+
220
+ func BenchmarkNotContains (b * testing.B ) {
221
+ for i := 0 ; i < b .N ; i ++ {
222
+ contains ([]string {"1" , "2" }, "3" )
223
+ }
224
+ }
225
+
226
+ func BenchmarkNotContainsLong50000 (b * testing.B ) {
227
+ var list []string
228
+
229
+ // Simulate a list of postal codes
230
+ for i := 0 ; i < 50000 ; i ++ {
231
+ list = append (list , fmt .Sprintf ("%d" , i ))
232
+ }
233
+
234
+ b .ResetTimer ()
235
+
236
+ for i := 0 ; i < b .N ; i ++ {
237
+ contains (list , "50000" )
238
+ }
239
+ }
240
+
202
241
func TestOneOf (t * testing.T ) {
203
242
cases := []testCase {
204
243
testCase {args : []interface {}{"a" , []interface {}{"a" , "b" }}, expected : true },
0 commit comments