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\Collection;
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public function testPartition(array $expected, iterable $iterable, callable $predicate): void
|
|
|
|
{
|
|
|
|
self::assertSame($expected, Arr\partition($iterable, $predicate));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
[['bar', 'baz'], ['foo', 'qux']],
|
|
|
|
new Collection\Vector(['foo', 'bar', 'baz', 'qux']),
|
|
|
|
fn (string $str) => Str\starts_with($str, 'b'),
|
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
[['bar', 'baz'], ['foo', 'qux']],
|
|
|
|
new Collection\Map(['foo', 'bar', 'baz', 'qux']),
|
|
|
|
fn (string $str) => Str\starts_with($str, 'b'),
|
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
[[], []],
|
|
|
|
[],
|
|
|
|
fn ($_) => false,
|
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
[[], ['foo', 'bar', 'baz', 'qux']],
|
|
|
|
new Collection\Map(['foo', 'bar', 'baz', 'qux']),
|
|
|
|
fn (string $str) => false,
|
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
[['foo', 'bar', 'baz', 'qux'], []],
|
|
|
|
new Collection\Map(['foo', 'bar', 'baz', 'qux']),
|
|
|
|
fn (string $str) => true,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|