2019-12-24 01:52:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Psl\Tests\Iter;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2020-07-16 17:11:54 +02:00
|
|
|
use Psl\Iter;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
final class DiffByKeyTest extends TestCase
|
2019-12-24 01:52:07 +01:00
|
|
|
{
|
2020-07-16 17:11:54 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
|
|
|
public function testDiffByKey(array $expected, iterable $first, iterable $second, iterable ...$rest): void
|
|
|
|
{
|
|
|
|
$result = Iter\diff_by_key($first, $second, ...$rest);
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame($expected, Iter\to_array_with_keys($result));
|
2020-07-16 17:11:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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]];
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|