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

27 lines
614 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-09-01 07:50:23 +02:00
use Psl\Iter;
use Psl\Str;
2019-12-24 01:52:07 +01:00
class PullWithKeyTest extends TestCase
{
2020-09-01 07:50:23 +02:00
public function testPull(): void
{
$result = Iter\pull_with_key(
Iter\range(0, 10),
fn($k, $v) => Str\chr($v + $k + 65),
fn($k, $v) => 2**($v+$k)
);
self::assertSame([
1 => 'A', 4 => 'C', 16 => 'E', 64 => 'G', 256 => 'I', 1024 => 'K',
4096 => 'M', 16384 => 'O', 65536 => 'Q', 262144 => 'S', 1048576 => 'U'
], Iter\to_array_with_keys($result));
}
2019-12-24 01:52:07 +01:00
}