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

49 lines
1014 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-17 23:33:18 +02:00
use Psl\Iter;
2019-12-24 01:52:07 +01:00
final class ZipTest extends TestCase
2019-12-24 01:52:07 +01:00
{
2020-08-17 23:33:18 +02:00
public function testZip(): void
{
$result = Iter\zip(
[1, 2, 3, 4],
[5, 6, 7, 8, 9],
[10, 11, 12]
);
static::assertCount(3, $result);
$k = $result->key();
$v = $result->current();
static::assertSame([0, 0, 0], $k);
static::assertSame([1, 5, 10], $v);
$result->next();
$k = $result->key();
$v = $result->current();
static::assertSame([1, 1, 1], $k);
static::assertSame([2, 6, 11], $v);
$result->next();
$k = $result->key();
$v = $result->current();
static::assertSame([2, 2, 2], $k);
static::assertSame([3, 7, 12], $v);
}
2020-09-01 07:52:09 +02:00
public function testZipWithZeroIterables(): void
{
$result = Iter\zip(...[]);
static::assertCount(0, $result);
2020-09-01 07:52:09 +02:00
}
2019-12-24 01:52:07 +01:00
}