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\Collection;
|
|
|
|
use Psl\Iter;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
|
|
|
class CountTest extends TestCase
|
|
|
|
{
|
2020-07-16 17:11:54 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
|
|
|
public function testCount(int $expected, iterable $iterable): void
|
|
|
|
{
|
|
|
|
self::assertSame($expected, Iter\count($iterable));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): iterable
|
|
|
|
{
|
|
|
|
yield [0, []];
|
|
|
|
yield [1, [null]];
|
|
|
|
yield [3, [1, 2, 3]];
|
|
|
|
yield [10, Iter\range(1, 10)];
|
|
|
|
yield [1, (fn () => yield 1 => 2)()];
|
|
|
|
yield [21, new Collection\Vector(Iter\range(0, 100, 5))];
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|