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 ProductTest extends TestCase
|
|
|
|
{
|
2020-09-01 07:50:23 +02:00
|
|
|
public function testProduct(): void
|
|
|
|
{
|
2020-09-05 17:23:37 +02:00
|
|
|
$result = Iter\product(Iter\range(1, 2), Iter\range(3, 4));
|
2020-09-01 07:50:23 +02:00
|
|
|
$entries = Iter\to_array(Iter\enumerate($result));
|
|
|
|
|
|
|
|
self::assertCount(4, $entries);
|
|
|
|
|
|
|
|
self::assertSame($entries[0], [[0, 0], [1, 3]]);
|
|
|
|
self::assertSame($entries[1], [[0, 1], [1, 4]]);
|
|
|
|
self::assertSame($entries[2], [[1, 0], [2, 3]]);
|
|
|
|
self::assertSame($entries[3], [[1, 1], [2, 4]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testProductEmpty(): void
|
|
|
|
{
|
2020-09-05 17:23:37 +02:00
|
|
|
$result = Iter\product(...[]);
|
2020-09-01 07:50:23 +02:00
|
|
|
$entries = Iter\to_array(Iter\enumerate($result));
|
|
|
|
|
|
|
|
self::assertCount(1, $entries);
|
|
|
|
|
|
|
|
self::assertSame($entries[0], [[], []]);
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|