endtoend-test-psl/tests/Psl/Iter/AllTest.php

36 lines
1.3 KiB
PHP
Raw Normal View History

2019-12-24 01:52:07 +01:00
<?php
declare(strict_types=1);
namespace Psl\Tests\Iter;
use PHPUnit\Framework\TestCase;
2020-07-07 15:17:36 +02:00
use Psl\Iter;
2019-12-24 01:52:07 +01:00
class AllTest extends TestCase
{
2020-07-07 15:17:36 +02:00
/**
* @dataProvider provideData
*/
public function testAll(bool $expected, iterable $iterable, callable $predicate): void
{
self::assertSame($expected, Iter\all($iterable, $predicate));
2020-07-07 15:17:36 +02:00
}
public function provideData(): iterable
{
yield [false, [false, true, true], fn (bool $value): bool => $value];
yield [false, [false, true, true], fn (bool $value): bool => !$value];
yield [true, [true, true, true], fn (bool $value): bool => $value];
yield [false, [true, true, true], fn (bool $value): bool => !$value];
yield [false, [false, false, false], fn (bool $value): bool => $value];
yield [true, [false, false, false], fn (bool $value): bool => !$value];
yield [true, [false, false, false], fn (bool $value): bool => true];
yield [false, [false, false, false], fn (bool $value): bool => false];
yield [false, [1, 2, 3], fn (int $i): bool => $i > 3];
yield [true, [4, 5, 6], fn (int $i): bool => $i > 3];
yield [false, [1, 2, 3, 4, 5, 6], fn (int $i): bool => $i > 3];
yield [true, [], fn (bool $value): bool => false];
}
2019-12-24 01:52:07 +01:00
}