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