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
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
final class ReverseTest extends TestCase
|
2019-12-24 01:52:07 +01:00
|
|
|
{
|
2020-09-01 07:50:23 +02:00
|
|
|
public function testReverse(): void
|
|
|
|
{
|
2020-09-01 07:56:15 +02:00
|
|
|
$result = Iter\reverse(['foo', 'bar', 'baz', 'qux']);
|
2020-09-01 07:50:23 +02:00
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame(['qux', 'baz', 'bar', 'foo'], Iter\to_array_with_keys($result));
|
2020-09-01 07:50:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testReverseEarlyReturnForEmptyIterables(): void
|
|
|
|
{
|
|
|
|
$result = Iter\reverse(Iter\to_iterator([]));
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame([], Iter\to_array($result));
|
2020-09-01 07:50:23 +02:00
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|