2019-12-24 01:52:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Psl\Tests\Iter;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2020-07-16 17:11:54 +02:00
|
|
|
use Psl\Iter;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
|
|
|
class ChunkTest extends TestCase
|
|
|
|
{
|
2020-07-16 17:11:54 +02:00
|
|
|
/**
|
|
|
|
* @psalm-template T
|
|
|
|
*
|
|
|
|
* @psalm-param list<list<T>> $expected
|
|
|
|
* @psalm-param iterable<T> $iterable
|
|
|
|
*
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
|
|
|
public function testChunk(array $expected, iterable $iterable, int $size): void
|
|
|
|
{
|
|
|
|
$chunks = Iter\chunk($iterable, $size);
|
|
|
|
|
|
|
|
self::assertSame($expected, Iter\to_array($chunks));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): iterable
|
|
|
|
{
|
|
|
|
yield [[[1], [2], [3]], Iter\range(1, 3), 1];
|
|
|
|
yield [[], [], 4];
|
|
|
|
yield [[[1, 2, 3], [4, 5, 6], [7, 8, 9]], Iter\range(1, 9), 3];
|
|
|
|
yield [[[1, 3, 5], [7, 9]], Iter\range(1, 9, 2), 3];
|
|
|
|
yield [[[1, 3], [5, 7], [9]], Iter\range(1, 9, 2), 2];
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|