| Total Complexity | 3 |
| Total Lines | 28 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class IterableReduceTest extends TestCase |
||
| 12 | { |
||
| 13 | use ProvideIterablesTrait; |
||
| 14 | |||
| 15 | public function provider() |
||
| 16 | { |
||
| 17 | return $this->provideIterables([2, 3, 4], true); |
||
| 18 | } |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @dataProvider provider |
||
| 22 | */ |
||
| 23 | public function test($values) |
||
| 24 | { |
||
| 25 | $result = iterable_reduce($values, function ($product, $value) { |
||
| 26 | return $product * $value; |
||
| 27 | }, 1); |
||
| 28 | |||
| 29 | $this->assertEquals(24, $result); |
||
| 30 | } |
||
| 31 | |||
| 32 | public function testEmpty() |
||
| 33 | { |
||
| 34 | $result = iterable_reduce(new \EmptyIterator(), function () { |
||
| 35 | return 10; |
||
| 36 | }, 1); |
||
| 37 | |||
| 38 | $this->assertEquals(1, $result); |
||
| 39 | } |
||
| 41 |