@@ 137-166 (lines=30) @@ | ||
134 | ->shouldReturn([2, 4, 4, 3]); |
|
135 | } |
|
136 | ||
137 | function it_can_reduce() |
|
138 | { |
|
139 | $this |
|
140 | ->reduce( |
|
141 | function ($temp, $item) { |
|
142 | return $temp + $item; |
|
143 | }, |
|
144 | 0 |
|
145 | ) |
|
146 | ->shouldReturn(9); |
|
147 | ||
148 | $this |
|
149 | ->reduce( |
|
150 | function ($temp, $item, $key) { |
|
151 | return $temp + $key + $item; |
|
152 | }, |
|
153 | 0 |
|
154 | ) |
|
155 | ->shouldReturn(15); |
|
156 | ||
157 | $this |
|
158 | ->reduce( |
|
159 | function ($temp, $item) { |
|
160 | return array_merge([$item], $temp); |
|
161 | }, |
|
162 | [] |
|
163 | ) |
|
164 | ->toArray() |
|
165 | ->shouldReturn([2, 3, 3, 1]); |
|
166 | } |
|
167 | ||
168 | function it_can_flatten() |
|
169 | { |
|
@@ 427-456 (lines=30) @@ | ||
424 | $it->valid()->shouldReturn(false); |
|
425 | } |
|
426 | ||
427 | function it_can_reduce_from_right() |
|
428 | { |
|
429 | $this |
|
430 | ->reduceRight( |
|
431 | function ($temp, $e) { |
|
432 | return $temp . $e; |
|
433 | }, |
|
434 | 0 |
|
435 | ) |
|
436 | ->shouldReturn('02331'); |
|
437 | ||
438 | $this |
|
439 | ->reduceRight( |
|
440 | function ($temp, $key, $item) { |
|
441 | return $temp + $key + $item; |
|
442 | }, |
|
443 | 0 |
|
444 | ) |
|
445 | ->shouldReturn(15); |
|
446 | ||
447 | $this |
|
448 | ->reduceRight( |
|
449 | function ($temp, $item) { |
|
450 | return array_merge($temp, [$item]); |
|
451 | }, |
|
452 | [] |
|
453 | ) |
|
454 | ->toArray() |
|
455 | ->shouldReturn([2, 3, 3, 1]); |
|
456 | } |
|
457 | ||
458 | function it_can_return_only_first_x_elements() |
|
459 | { |