endtoend-test-psl/tests/Psl/Iter/DiffByKeyTest.php

34 lines
852 B
PHP
Raw Normal View History

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
class DiffByKeyTest extends TestCase
{
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);
self::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]];
}
2019-12-24 01:52:07 +01:00
}