@@ -950,47 +950,85 @@ func getReduceCases(t *testing.T, builder baseCollIntBuilder) []*baseTestCase {
950950 {
951951 name : "Reduce() on empty collection" ,
952952 coll : builder .Empty (),
953- args : baseIntArgs {reducer : func (acc int , i int , current int ) int {
954- return acc + current
953+ args : baseIntArgs {reducer : func (acc int , _ int , current int ) int {
954+ return acc * 10 + current
955955 }},
956956 want1 : 0 ,
957957 want2 : ErrEmptyCollection ,
958958 },
959959 {
960960 name : "Fold() on one-item collection" ,
961961 coll : builder .One (),
962- args : baseIntArgs {reducer : func (acc int , i int , current int ) int {
963- return acc + current
962+ args : baseIntArgs {reducer : func (acc int , _ int , current int ) int {
963+ return acc * 10 + current
964964 }},
965965 want1 : 111 ,
966966 want2 : nil ,
967967 },
968968 {
969969 name : "Fold() on three-item collection" ,
970970 coll : builder .Three (),
971- args : baseIntArgs {reducer : func (acc int , i int , current int ) int {
972- return acc + current
971+ args : baseIntArgs {reducer : func (acc int , _ int , current int ) int {
972+ return acc * 10 + current
973973 }},
974- want1 : 666 ,
974+ want1 : 13653 ,
975975 want2 : nil ,
976976 },
977+ }
978+ }
979+
980+ func testReduce (t * testing.T , builder baseCollIntBuilder ) {
981+ cases := getReduceCases (t , builder )
982+ for _ , tt := range cases {
983+ t .Run (tt .name , func (t * testing.T ) {
984+ got1 , got2 := tt .coll .Reduce (tt .args .reducer )
985+ if ! reflect .DeepEqual (got1 , tt .want1 ) {
986+ t .Errorf ("Reduce() = %v, want1 %v" , got1 , tt .want1 )
987+ }
988+ if ! reflect .DeepEqual (got2 , tt .want2 ) {
989+ t .Errorf ("Reduce() = %v, want1 %v" , got2 , tt .want2 )
990+ }
991+ })
992+ }
993+ }
994+
995+ func getReduceRevCases (t * testing.T , builder baseCollIntBuilder ) []* baseTestCase {
996+ return []* baseTestCase {
977997 {
978- name : "Fold() on three-item collection, include index" ,
998+ name : "Reduce() on empty collection" ,
999+ coll : builder .Empty (),
1000+ args : baseIntArgs {reducer : func (acc int , _ int , current int ) int {
1001+ return acc * 10 + current
1002+ }},
1003+ want1 : 0 ,
1004+ want2 : ErrEmptyCollection ,
1005+ },
1006+ {
1007+ name : "Fold() on one-item collection" ,
1008+ coll : builder .One (),
1009+ args : baseIntArgs {reducer : func (acc int , _ int , current int ) int {
1010+ return acc * 10 + current
1011+ }},
1012+ want1 : 111 ,
1013+ want2 : nil ,
1014+ },
1015+ {
1016+ name : "Fold() on three-item collection" ,
9791017 coll : builder .Three (),
980- args : baseIntArgs {reducer : func (acc int , i int , current int ) int {
981- return acc + i + current
1018+ args : baseIntArgs {reducer : func (acc int , _ int , current int ) int {
1019+ return acc * 10 + current
9821020 }},
983- want1 : 0 + 111 + 1 + 222 + 2 + 333 ,
1021+ want1 : 35631 ,
9841022 want2 : nil ,
9851023 },
9861024 }
9871025}
9881026
989- func testReduce (t * testing.T , builder baseCollIntBuilder ) {
990- cases := getReduceCases (t , builder )
1027+ func testReduceRev (t * testing.T , builder baseCollIntBuilder ) {
1028+ cases := getReduceRevCases (t , builder )
9911029 for _ , tt := range cases {
9921030 t .Run (tt .name , func (t * testing.T ) {
993- got1 , got2 := tt .coll .Reduce (tt .args .reducer )
1031+ got1 , got2 := tt .coll .ReduceRev (tt .args .reducer )
9941032 if ! reflect .DeepEqual (got1 , tt .want1 ) {
9951033 t .Errorf ("Reduce() = %v, want1 %v" , got1 , tt .want1 )
9961034 }
0 commit comments