endtoend-test-psl/tests/Psl/Iter/DiffByKeyTest.php
2020-10-15 11:05:30 +02:00

34 lines
860 B
PHP

<?php
declare(strict_types=1);
namespace Psl\Tests\Iter;
use PHPUnit\Framework\TestCase;
use Psl\Iter;
final class DiffByKeyTest extends TestCase
{
/**
* @dataProvider provideData
*/
public function testDiffByKey(array $expected, iterable $first, iterable $second, iterable ...$rest): void
{
$result = Iter\diff_by_key($first, $second, ...$rest);
static::assertSame($expected, Iter\to_array_with_keys($result));
}
public function provideData(): iterable
{
yield [[], [], [], []];
yield [[], [], [1, 2, 3]];
yield [[], [], [1, 2, 3], []];
yield [[], [], [1, 2, 3], [], [4, 5]];
yield [[1, 2], [1, 2], [], []];
yield [[6 => 7, 7 => 8], Iter\range(1, 8), Iter\range(1, 6), []];
yield [[7 => 8], Iter\range(1, 8), Iter\range(1, 6), [6 => 7]];
}
}