@@ -33,6 +33,11 @@ private static function fSumAggregator(): callable
3333 };
3434 }
3535
36+ private static function fEmptyFunction (): callable
37+ {
38+ return static function () {};
39+ }
40+
3641 public function createCollection (array $ els ): Collection
3742 {
3843 return new ArrayList ($ els );
@@ -207,9 +212,10 @@ public function mapConvertingChecking($input, $modifier, $expected): void
207212 public function reduceCases (): array
208213 {
209214 return [
210- [[1 ,2 ,3 ], self ::fSumAggregator (), 6 ],
211- [[1 , 2 , 4 ], self ::fCountAggregator (), 3 ],
212- [[], self ::fSumAggregator (), 0 ]
215+ [[1 ,2 ,3 ], self ::fSumAggregator (), 4 , 10 ],
216+ [[1 , 2 , 4 ], self ::fCountAggregator (), 0 , 3 ],
217+ [[], self ::fSumAggregator (), null , null ],
218+ [[], self ::fEmptyFunction (), [], []]
213219 ];
214220 }
215221
@@ -218,15 +224,16 @@ public function reduceCases(): array
218224 * @test
219225 * @param $input
220226 * @param $accumulator
227+ * @param $initialValue
221228 * @param $expected
222229 */
223- public function reduceChecking ($ input , $ accumulator , $ expected ): void
230+ public function reduceChecking ($ input , $ accumulator , $ initialValue , $ expected ): void
224231 {
225232 $ actual = $ this ->createCollection ($ input )
226233 ->stream ()
227- ->reduce ($ accumulator );
234+ ->reduce ($ accumulator, $ initialValue );
228235
229- $ this ->assertEquals ($ expected , $ actual );
236+ $ this ->assertSame ($ expected , $ actual );
230237 }
231238
232239 public function aggregateCases (): array
@@ -286,11 +293,11 @@ public function findAnyElementChecking($input): void
286293 public function sortDataSet (): array
287294 {
288295 return [
289- // input | comparator | min| max | sorted
290- [[1 , 2 , 3 , 4 ], self ::fIntComparator (), 1 , 4 , [1 , 2 , 3 , 4 ]],
291- [[3 , 12 , 1 , 4 ], self ::fIntComparator (), 1 , 12 , [1 , 3 , 4 , 12 ]],
292- [[], self ::fIntComparator (), null , null , []],
293- [[1 ], self ::fIntComparator (), 1 , 1 , [1 ]],
296+ // input | comparator | min | max | sorted
297+ [[1 , 2 , 3 , 4 ], self ::fIntComparator (), 1 , 4 , [1 , 2 , 3 , 4 ]],
298+ [[3 , 12 , 1 , 4 ], self ::fIntComparator (), 1 , 12 , [1 , 3 , 4 , 12 ]],
299+ [[], self ::fIntComparator (), null , null , []],
300+ [[1 ], self ::fIntComparator (), 1 , 1 , [1 ]],
294301 ];
295302 }
296303
0 commit comments