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

33 lines
881 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-08-08 06:35:34 +02:00
use Psl\Collection;
use Psl\Iter;
2019-12-24 01:52:07 +01:00
class FlipTest extends TestCase
{
2020-08-08 06:35:34 +02:00
public function testFlip(): void
{
$a = new Collection\MutableVector(['a', 'b']);
$b = new Collection\MutableVector(['c', 'd']);
2020-09-01 03:03:19 +02:00
$iterable = Iter\Iterator::create(['a' => $a, 'b' => $b]);
2020-08-08 06:35:34 +02:00
static::assertSame('a', Iter\first_key($iterable));
static::assertSame($a, Iter\first($iterable));
static::assertSame('b', Iter\last_key($iterable));
static::assertSame($b, Iter\last($iterable));
$result = Iter\flip($iterable);
static::assertSame($a, Iter\first_key($result));
static::assertSame('a', Iter\first($result));
static::assertSame($b, Iter\last_key($result));
static::assertSame('b', Iter\last($result));
}
2019-12-24 01:52:07 +01:00
}