@@ -6,13 +6,13 @@ import (
66 "testing"
77)
88
9- type baseIntArgs = testArgs [Base [int ], int ]
10- type baseTestCase = testCase [Base [int ], int ]
11- type baseCollIntBuilder = testCollectionBuilder [Base [int ], int ]
9+ type baseIntArgs = testArgs [baseInternal [int ], int ]
10+ type baseTestCase = testCase [baseInternal [int ], int ]
11+ type baseCollIntBuilder = testCollectionBuilder [baseInternal [int ]]
1212
13- type baseIntPairArgs = testArgs [Base [Pair [int , int ]], Pair [int , int ]]
14- type baseIntPairTestCase = testCase [Base [Pair [int , int ]], Pair [int , int ]]
15- type baseCollIntPairBuilder = testPairCollectionBuilder [Base [Pair [int , int ]]]
13+ type baseIntPairArgs = testArgs [baseInternal [Pair [int , int ]], Pair [int , int ]]
14+ type baseIntPairTestCase = testCase [baseInternal [Pair [int , int ]], Pair [int , int ]]
15+ type baseCollIntPairBuilder = testPairCollectionBuilder [baseInternal [Pair [int , int ]]]
1616
1717func getContainsCases (builder baseCollIntBuilder ) []baseTestCase {
1818 return []baseTestCase {
@@ -598,6 +598,50 @@ func testFind(t *testing.T, builder baseCollIntBuilder) {
598598 }
599599}
600600
601+ func getFindCasesWithDupes (builder baseCollIntPairBuilder ) []* baseIntPairTestCase {
602+ return []* baseIntPairTestCase {
603+ {
604+ name : "Find() on six-item collection, first one" ,
605+ coll : builder .SixWithDuplicates (),
606+ args : baseIntPairArgs {
607+ predicate : func (i int , p Pair [int , int ]) bool { return true },
608+ defaultValue : nil ,
609+ },
610+ want1 : NewPair (1 , 111 ),
611+ },
612+ {
613+ name : "Find() on six-item collection, second one" ,
614+ coll : builder .SixWithDuplicates (),
615+ args : baseIntPairArgs {
616+ predicate : func (i int , p Pair [int , int ]) bool { return p .Val () == 222 },
617+ defaultValue : nil ,
618+ },
619+ want1 : NewPair (2 , 222 ),
620+ },
621+ {
622+ name : "Find() on six-item collection, not found" ,
623+ coll : builder .SixWithDuplicates (),
624+ args : baseIntPairArgs {
625+ predicate : func (i int , p Pair [int , int ]) bool { return p .Val () == 999 },
626+ defaultValue : nil ,
627+ },
628+ want1 : nil ,
629+ },
630+ }
631+ }
632+
633+ func testFindWithDupes (t * testing.T , builder baseCollIntPairBuilder ) {
634+ cases := getFindCasesWithDupes (builder )
635+ for _ , tt := range cases {
636+ t .Run (tt .name , func (t * testing.T ) {
637+ got := tt .coll .Find (tt .args .predicate , tt .args .defaultValue )
638+ if ! reflect .DeepEqual (got , tt .want1 ) {
639+ t .Errorf ("Find() = %v, want1 %v" , got , tt .want1 )
640+ }
641+ })
642+ }
643+ }
644+
601645func getFindLastCases (builder baseCollIntBuilder ) []* baseTestCase {
602646 return []* baseTestCase {
603647 {
@@ -659,6 +703,50 @@ func getFindLastCases(builder baseCollIntBuilder) []*baseTestCase {
659703 }
660704}
661705
706+ func getFindLastCasesWithDupes (builder baseCollIntPairBuilder ) []* baseIntPairTestCase {
707+ return []* baseIntPairTestCase {
708+ {
709+ name : "FindLast() on six-item collection, first one" ,
710+ coll : builder .SixWithDuplicates (),
711+ args : baseIntPairArgs {
712+ predicate : func (i int , p Pair [int , int ]) bool { return true },
713+ defaultValue : nil ,
714+ },
715+ want1 : NewPair (6 , 333 ),
716+ },
717+ {
718+ name : "FindLast() on six-item collection, second one" ,
719+ coll : builder .SixWithDuplicates (),
720+ args : baseIntPairArgs {
721+ predicate : func (i int , p Pair [int , int ]) bool { return p .Val () == 222 },
722+ defaultValue : nil ,
723+ },
724+ want1 : NewPair (5 , 222 ),
725+ },
726+ {
727+ name : "FindLast() on six-item collection, not found" ,
728+ coll : builder .SixWithDuplicates (),
729+ args : baseIntPairArgs {
730+ predicate : func (i int , p Pair [int , int ]) bool { return p .Val () == 999 },
731+ defaultValue : nil ,
732+ },
733+ want1 : nil ,
734+ },
735+ }
736+ }
737+
738+ func testFindLastWithDupes (t * testing.T , builder baseCollIntPairBuilder ) {
739+ cases := getFindLastCasesWithDupes (builder )
740+ for _ , tt := range cases {
741+ t .Run (tt .name , func (t * testing.T ) {
742+ got := tt .coll .FindLast (tt .args .predicate , tt .args .defaultValue )
743+ if ! reflect .DeepEqual (got , tt .want1 ) {
744+ t .Errorf ("FindLast() = %v, want1 %v" , got , tt .want1 )
745+ }
746+ })
747+ }
748+ }
749+
662750func testFindLast (t * testing.T , builder baseCollIntBuilder ) {
663751 cases := getFindLastCases (builder )
664752 for _ , tt := range cases {
@@ -1005,7 +1093,7 @@ func getSearchPairCases(builder baseCollIntPairBuilder) []*baseIntPairTestCase {
10051093 name : "Search() pair on six-item collection, found first occurrence" ,
10061094 coll : builder .SixWithDuplicates (),
10071095 args : baseIntPairArgs {predicate : func (i int , v Pair [int , int ]) bool {
1008- return v .Value () == 111
1096+ return v .Val () == 111
10091097 }},
10101098 want1 : NewPair (1 , 111 ),
10111099 want2 : true ,
@@ -1014,7 +1102,7 @@ func getSearchPairCases(builder baseCollIntPairBuilder) []*baseIntPairTestCase {
10141102 name : "Search() pair on six-item collection, found first occurrence" ,
10151103 coll : builder .SixWithDuplicates (),
10161104 args : baseIntPairArgs {predicate : func (i int , v Pair [int , int ]) bool {
1017- return v .Value () == 222
1105+ return v .Val () == 222
10181106 }},
10191107 want1 : NewPair (2 , 222 ),
10201108 want2 : true ,
@@ -1023,7 +1111,7 @@ func getSearchPairCases(builder baseCollIntPairBuilder) []*baseIntPairTestCase {
10231111 name : "Search() pair on six-item collection, found first occurrence" ,
10241112 coll : builder .SixWithDuplicates (),
10251113 args : baseIntPairArgs {predicate : func (i int , v Pair [int , int ]) bool {
1026- return v .Value () == 333
1114+ return v .Val () == 333
10271115 }},
10281116 want1 : NewPair (3 , 333 ),
10291117 want2 : true ,
@@ -1199,7 +1287,7 @@ func getSearchRevPairCases(builder baseCollIntPairBuilder) []*baseIntPairTestCas
11991287 name : "SearchRev() on six-item collection, found first occurrence" ,
12001288 coll : builder .SixWithDuplicates (),
12011289 args : baseIntPairArgs {predicate : func (i int , v Pair [int , int ]) bool {
1202- return v .Value () == 111
1290+ return v .Val () == 111
12031291 }},
12041292 want1 : NewPair (4 , 111 ),
12051293 want2 : true ,
@@ -1208,7 +1296,7 @@ func getSearchRevPairCases(builder baseCollIntPairBuilder) []*baseIntPairTestCas
12081296 name : "SearchRev() on six-item collection, found first occurrence" ,
12091297 coll : builder .SixWithDuplicates (),
12101298 args : baseIntPairArgs {predicate : func (i int , v Pair [int , int ]) bool {
1211- return v .Value () == 222
1299+ return v .Val () == 222
12121300 }},
12131301 want1 : NewPair (5 , 222 ),
12141302 want2 : true ,
@@ -1217,7 +1305,7 @@ func getSearchRevPairCases(builder baseCollIntPairBuilder) []*baseIntPairTestCas
12171305 name : "SearchRev() on six-item collection, found first occurrence" ,
12181306 coll : builder .SixWithDuplicates (),
12191307 args : baseIntPairArgs {predicate : func (i int , v Pair [int , int ]) bool {
1220- return v .Value () == 333
1308+ return v .Val () == 333
12211309 }},
12221310 want1 : NewPair (6 , 333 ),
12231311 want2 : true ,
0 commit comments