mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-12-12 09:09:45 +01:00
56 lines
1.4 KiB
PHP
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,
|
|
],
|
|
];
|
|
}
|
|
}
|