endtoend-test-psl/tests/Psl/Arr/SortTest.php

43 lines
905 B
PHP
Raw Normal View History

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\Iter;
2019-12-24 01:52:07 +01:00
class SortTest extends TestCase
{
2019-12-25 00:35:14 +01:00
/**
* @dataProvider provideData
*/
public function testSort(array $expected, iterable $iterable, ?callable $comparator = null): void
{
static::assertSame($expected, Arr\sort($iterable, $comparator));
}
public function provideData(): array
{
return [
[
['a', 'b', 'c'],
new Collection\Vector(['c', 'a', 'b']),
],
[
[8, 9, 10],
2020-02-21 02:03:40 +01:00
new Collection\MutableVector(Iter\range(8, 10)),
2019-12-25 00:35:14 +01:00
fn (int $a, int $b) => $a <=> $b ? -1 : 1,
],
[
['bar', 'baz'],
['foo' => 'bar', 'bar' => 'baz'],
],
];
}
2019-12-24 01:52:07 +01:00
}