2019-12-24 01:52:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Psl\Tests\Arr;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-12-25 00:35:14 +01:00
|
|
|
use Psl\Arr;
|
|
|
|
use Psl\Str;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
|
|
|
class PartitionTest extends TestCase
|
|
|
|
{
|
2019-12-25 00:35:14 +01:00
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
2020-08-27 16:14:37 +02:00
|
|
|
public function testPartition(array $expected, array $array, callable $predicate): void
|
2019-12-25 00:35:14 +01:00
|
|
|
{
|
2020-08-27 16:14:37 +02:00
|
|
|
self::assertSame($expected, Arr\partition($array, $predicate));
|
2019-12-25 00:35:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
[['bar', 'baz'], ['foo', 'qux']],
|
2020-08-27 16:14:37 +02:00
|
|
|
['foo', 'bar', 'baz', 'qux'],
|
2019-12-25 00:35:14 +01:00
|
|
|
fn (string $str) => Str\starts_with($str, 'b'),
|
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
[['bar', 'baz'], ['foo', 'qux']],
|
2020-08-27 16:14:37 +02:00
|
|
|
['foo', 'bar', 'baz', 'qux'],
|
2019-12-25 00:35:14 +01:00
|
|
|
fn (string $str) => Str\starts_with($str, 'b'),
|
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
[[], []],
|
|
|
|
[],
|
|
|
|
fn ($_) => false,
|
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
[[], ['foo', 'bar', 'baz', 'qux']],
|
2020-08-27 16:14:37 +02:00
|
|
|
['foo', 'bar', 'baz', 'qux'],
|
2019-12-25 00:35:14 +01:00
|
|
|
fn (string $str) => false,
|
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
[['foo', 'bar', 'baz', 'qux'], []],
|
2020-08-27 16:14:37 +02:00
|
|
|
['foo', 'bar', 'baz', 'qux'],
|
2019-12-25 00:35:14 +01:00
|
|
|
fn (string $str) => true,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|