@@ -1449,6 +1449,7 @@ func getMapRemoveMatchingCases(builder baseMapCollIntBuilder) []baseMapTestCase
14491449 want2 : map [int ]int {},
14501450 want3 : map [int ]int {},
14511451 want4 : map [int ]int {},
1452+ want5 : 0 ,
14521453 },
14531454 {
14541455 name : "RemoveMatching() on one-item collection, found" ,
@@ -1458,6 +1459,7 @@ func getMapRemoveMatchingCases(builder baseMapCollIntBuilder) []baseMapTestCase
14581459 want2 : map [int ]int {},
14591460 want3 : map [int ]int {},
14601461 want4 : map [int ]int {},
1462+ want5 : 1 ,
14611463 },
14621464 {
14631465 name : "RemoveMatching() on one-item collection, not found" ,
@@ -1467,6 +1469,7 @@ func getMapRemoveMatchingCases(builder baseMapCollIntBuilder) []baseMapTestCase
14671469 want2 : map [int ]int {1 : 111 },
14681470 want3 : map [int ]int {1 : 0 },
14691471 want4 : map [int ]int {111 : 1 },
1472+ want5 : 0 ,
14701473 },
14711474 {
14721475 name : "RemoveMatching() on three-item collection, found all" ,
@@ -1476,6 +1479,7 @@ func getMapRemoveMatchingCases(builder baseMapCollIntBuilder) []baseMapTestCase
14761479 want2 : map [int ]int {},
14771480 want3 : map [int ]int {},
14781481 want4 : map [int ]int {},
1482+ want5 : 3 ,
14791483 },
14801484 {
14811485 name : "RemoveMatching() on three-item collection, found none" ,
@@ -1485,6 +1489,7 @@ func getMapRemoveMatchingCases(builder baseMapCollIntBuilder) []baseMapTestCase
14851489 want2 : map [int ]int {1 : 111 , 2 : 222 , 3 : 333 },
14861490 want3 : map [int ]int {1 : 0 , 2 : 1 , 3 : 2 },
14871491 want4 : map [int ]int {111 : 1 , 222 : 1 , 333 : 1 },
1492+ want5 : 0 ,
14881493 },
14891494 {
14901495 name : "RemoveMatching() on three-item collection, found first" ,
@@ -1494,6 +1499,7 @@ func getMapRemoveMatchingCases(builder baseMapCollIntBuilder) []baseMapTestCase
14941499 want2 : map [int ]int {2 : 222 , 3 : 333 },
14951500 want3 : map [int ]int {2 : 0 , 3 : 1 },
14961501 want4 : map [int ]int {222 : 1 , 333 : 1 },
1502+ want5 : 1 ,
14971503 },
14981504 {
14991505 name : "RemoveMatching() on three-item collection, found middle" ,
@@ -1503,6 +1509,7 @@ func getMapRemoveMatchingCases(builder baseMapCollIntBuilder) []baseMapTestCase
15031509 want2 : map [int ]int {1 : 111 , 3 : 333 },
15041510 want3 : map [int ]int {1 : 0 , 3 : 1 },
15051511 want4 : map [int ]int {111 : 1 , 333 : 1 },
1512+ want5 : 1 ,
15061513 },
15071514 {
15081515 name : "RemoveMatching() on three-item collection, found last" ,
@@ -1512,6 +1519,17 @@ func getMapRemoveMatchingCases(builder baseMapCollIntBuilder) []baseMapTestCase
15121519 want2 : map [int ]int {1 : 111 , 2 : 222 },
15131520 want3 : map [int ]int {1 : 0 , 2 : 1 },
15141521 want4 : map [int ]int {111 : 1 , 222 : 1 },
1522+ want5 : 1 ,
1523+ },
1524+ {
1525+ name : "RemoveMatching() on three-item collection, found even" ,
1526+ coll : builder .Three (),
1527+ args : baseMapIntArgs {predicate : func (p Pair [int , int ]) bool { return p .Val ()% 2 != 0 }},
1528+ want1 : []Pair [int , int ]{NewPair (2 , 222 )},
1529+ want2 : map [int ]int {2 : 222 },
1530+ want3 : map [int ]int {2 : 0 },
1531+ want4 : map [int ]int {222 : 1 },
1532+ want5 : 2 ,
15151533 },
15161534 }
15171535}
@@ -1520,7 +1538,7 @@ func testMapRemoveMatching(t *testing.T, builder baseMapCollIntBuilder) {
15201538 cases := getMapRemoveMatchingCases (builder )
15211539 for _ , tt := range cases {
15221540 t .Run (tt .name , func (t * testing.T ) {
1523- tt .coll .RemoveMatching (tt .args .predicate )
1541+ count := tt .coll .RemoveMatching (tt .args .predicate )
15241542 actualSlice := builder .extractUnderlyingSlice (tt .coll )
15251543 actualMap := builder .extractUnderlyingMap (tt .coll )
15261544 actualKP := builder .extractUnderlyingKp (tt .coll )
@@ -1539,6 +1557,9 @@ func testMapRemoveMatching(t *testing.T, builder baseMapCollIntBuilder) {
15391557 t .Errorf ("RemoveMatching() did not remove correctly from values counter" )
15401558 }
15411559 }
1560+ if count != tt .want5 {
1561+ t .Errorf ("RemoveMatching() returned wrong count: %v, but wanted = %v" , count , tt .want5 )
1562+ }
15421563 })
15431564 }
15441565}
0 commit comments