mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-12-11 16:49:40 +01:00
27 lines
705 B
PHP
27 lines
705 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Psl\Tests\Iter;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psl\Iter;
|
|
|
|
class ReduceTest extends TestCase
|
|
{
|
|
/**
|
|
* @dataProvider provideData
|
|
*/
|
|
public function testReduce($expected, iterable $iterable, callable $function, $initial = null): void
|
|
{
|
|
self::assertSame($expected, Iter\reduce($iterable, $function, $initial));
|
|
}
|
|
|
|
public function provideData(): iterable
|
|
{
|
|
yield [null, [], fn ($accumulator, $k, $v) => $accumulator, null];
|
|
yield [6, [1, 2, 3], fn ($accumulator, $k, $v) => $accumulator + $v, 0];
|
|
yield [6, Iter\to_iterator([1, 2, 3]), fn ($accumulator, $k, $v) => $accumulator + $v, 0];
|
|
}
|
|
}
|