endtoend-test-psl/tests/Psl/Dict/PartitionTest.php
2021-02-16 00:23:01 +01:00

56 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Psl\Tests\Dict;
use PHPUnit\Framework\TestCase;
use Psl\Dict;
use Psl\Str;
final class PartitionTest extends TestCase
{
/**
* @dataProvider provideData
*/
public function testPartition(array $expected, array $array, callable $predicate): void
{
static::assertSame($expected, Dict\partition($array, $predicate));
}
public function provideData(): array
{
return [
[
[[1 => 'bar', 2 => 'baz'], [0 => 'foo', 3 => 'qux']],
['foo', 'bar', 'baz', 'qux'],
static fn (string $str) => Str\starts_with($str, 'b'),
],
[
[[0 => 'foo', 3 => 'qux'], [1 => 'bar', 2 => 'baz']],
['foo', 'bar', 'baz', 'qux'],
static fn (string $str) => !Str\starts_with($str, 'b'),
],
[
[[], []],
[],
static fn ($_) => false,
],
[
[[], ['foo', 'bar', 'baz', 'qux']],
['foo', 'bar', 'baz', 'qux'],
static fn (string $str) => false,
],
[
[['foo', 'bar', 'baz', 'qux'], []],
['foo', 'bar', 'baz', 'qux'],
static fn (string $str) => true,
],
];
}
}