@@ -24,49 +24,28 @@ func testContainsElement() func(*testing.T) {
2424 list2 := []int {1 , 2 }
2525 simpleMap := map [any ]any {"Foo" : "Bar" }
2626
27- ok , found := containsElement ("Hello World" , "World" )
28- True (t , ok )
29- True (t , found )
30-
31- ok , found = containsElement (list1 , "Foo" )
32- True (t , ok )
33- True (t , found )
34-
35- ok , found = containsElement (list1 , "Bar" )
36- True (t , ok )
37- True (t , found )
38-
39- ok , found = containsElement (list2 , 1 )
40- True (t , ok )
41- True (t , found )
42-
43- ok , found = containsElement (list2 , 2 )
44- True (t , ok )
45- True (t , found )
46-
47- ok , found = containsElement (list1 , "Foo!" )
48- True (t , ok )
49- False (t , found )
50-
51- ok , found = containsElement (list2 , 3 )
52- True (t , ok )
53- False (t , found )
54-
55- ok , found = containsElement (list2 , "1" )
56- True (t , ok )
57- False (t , found )
58-
59- ok , found = containsElement (simpleMap , "Foo" )
60- True (t , ok )
61- True (t , found )
62-
63- ok , found = containsElement (simpleMap , "Bar" )
64- True (t , ok )
65- False (t , found )
27+ checkContains := func (list any , elem any , expectOK , expectFound bool ) {
28+ t .Helper ()
29+ ok , found := containsElement (list , elem )
30+ if ok != expectOK {
31+ t .Errorf ("containsElement(%v, %v): expected ok=%v, got %v" , list , elem , expectOK , ok )
32+ }
33+ if found != expectFound {
34+ t .Errorf ("containsElement(%v, %v): expected found=%v, got %v" , list , elem , expectFound , found )
35+ }
36+ }
6637
67- ok , found = containsElement (1433 , "1" )
68- False (t , ok )
69- False (t , found )
38+ checkContains ("Hello World" , "World" , true , true )
39+ checkContains (list1 , "Foo" , true , true )
40+ checkContains (list1 , "Bar" , true , true )
41+ checkContains (list2 , 1 , true , true )
42+ checkContains (list2 , 2 , true , true )
43+ checkContains (list1 , "Foo!" , true , false )
44+ checkContains (list2 , 3 , true , false )
45+ checkContains (list2 , "1" , true , false )
46+ checkContains (simpleMap , "Foo" , true , true )
47+ checkContains (simpleMap , "Bar" , true , false )
48+ checkContains (1433 , "1" , false , false )
7049 }
7150}
7251
@@ -76,14 +55,22 @@ func testGetLen() func(*testing.T) {
7655
7756 for v := range collectionImplGetLenFalseCases () {
7857 l , ok := getLen (v )
79- False (t , ok , "Expected getLen fail to get length of %#v" , v )
80- Equal (t , 0 , l , "getLen should return 0 for %#v" , v )
58+ if ok {
59+ t .Errorf ("expected getLen to fail for %#v" , v )
60+ }
61+ if l != 0 {
62+ t .Errorf ("expected getLen to return 0 for %#v, got %d" , v , l )
63+ }
8164 }
8265
8366 for c := range collectionImplGetLenTrueCases () {
8467 l , ok := getLen (c .v )
85- True (t , ok , "Expected getLen success to get length of %#v" , c .v )
86- Equal (t , c .l , l )
68+ if ! ok {
69+ t .Errorf ("expected getLen to succeed for %#v" , c .v )
70+ }
71+ if c .l != l {
72+ t .Errorf ("expected length %d for %#v, got %d" , c .l , c .v , l )
73+ }
8774 }
8875 }
8976}
0 commit comments