2019-12-24 01:52:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Psl\Tests\Iter;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2020-09-01 07:50:23 +02:00
|
|
|
use Psl\Iter;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
|
|
|
class LastKeyTest extends TestCase
|
|
|
|
{
|
2020-09-01 07:50:23 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
|
|
|
public function testLastKey($expected, iterable $iterable): void
|
|
|
|
{
|
|
|
|
$result = Iter\last_key($iterable);
|
|
|
|
|
|
|
|
self::assertSame($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): iterable
|
|
|
|
{
|
|
|
|
yield [3, [1, 2, 3, 4]];
|
|
|
|
yield [3, Iter\to_iterator([1, 2, 3, 4])];
|
|
|
|
yield [3, Iter\range(1, 4)];
|
|
|
|
yield [4, Iter\range(4, 8)];
|
|
|
|
yield [null, []];
|
|
|
|
yield [0, [null]];
|
|
|
|
yield [1, [null, null]];
|
2020-09-01 07:56:15 +02:00
|
|
|
yield [[1, 2], (fn () => yield [1, 2] => 'hello')()];
|
2020-09-01 07:50:23 +02:00
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|