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\Collection;
|
|
|
|
use Psl\Iter;
|
2020-10-15 10:18:03 +02:00
|
|
|
use SplDoublyLinkedList;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
final class LastTest extends TestCase
|
2019-12-24 01:52:07 +01:00
|
|
|
{
|
2020-09-01 07:50:23 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
|
|
|
public function testLast($expected, iterable $iterable): void
|
|
|
|
{
|
|
|
|
$result = Iter\last($iterable);
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame($expected, $result);
|
2020-09-01 07:50:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): iterable
|
|
|
|
{
|
|
|
|
yield [null, []];
|
2020-10-15 10:18:03 +02:00
|
|
|
yield [null, new SplDoublyLinkedList()];
|
2020-09-01 07:50:23 +02:00
|
|
|
yield ['d', ['a' => 'b', 'c' => 'd']];
|
|
|
|
yield ['b', ['a', 'b']];
|
|
|
|
yield ['b', new Collection\Vector(['a', 'b'])];
|
|
|
|
yield ['b', new Collection\Vector(['b'])];
|
|
|
|
yield ['d', new Collection\Map(['a' => 'b', 'c' => 'd'])];
|
|
|
|
yield [null, (static function () {
|
|
|
|
yield null => null;
|
|
|
|
})()];
|
|
|
|
yield [null, (static function () {
|
|
|
|
return;
|
|
|
|
yield;
|
|
|
|
})()];
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|