|
11 | 11 |
|
12 | 12 | use function Cdn77\Functions\mapFromEntries;
|
13 | 13 | use function Cdn77\Functions\mapFromIterable;
|
| 14 | +use function Cdn77\Functions\mappedQueuesFromIterable; |
14 | 15 | use function Cdn77\Functions\mappedSetsFromIterable;
|
15 | 16 | use function Cdn77\Functions\setFromIterable;
|
16 | 17 | use function Cdn77\Functions\vectorFromIterable;
|
17 | 18 |
|
18 | 19 | #[CoversFunction('Cdn77\Functions\mapFromIterable')]
|
| 20 | +#[CoversFunction('Cdn77\Functions\mappedQueuesFromIterable')] |
19 | 21 | #[CoversFunction('Cdn77\Functions\mappedSetsFromIterable')]
|
20 | 22 | #[CoversFunction('Cdn77\Functions\setFromIterable')]
|
21 | 23 | #[CoversFunction('Cdn77\Functions\vectorFromIterable')]
|
@@ -53,6 +55,32 @@ public function testMapFromIterable(): void
|
53 | 55 | self::assertFalse($map->get(4));
|
54 | 56 | }
|
55 | 57 |
|
| 58 | + public function testMappedQueuesFromIterable(): void |
| 59 | + { |
| 60 | + /** @var callable():Generator<int, string> $iterableFactory */ |
| 61 | + $iterableFactory = static function (): Generator { |
| 62 | + yield 1 => 'a'; |
| 63 | + yield 1 => 'b'; |
| 64 | + yield 2 => 'c'; |
| 65 | + yield 2 => 'd'; |
| 66 | + }; |
| 67 | + |
| 68 | + $map = mappedQueuesFromIterable( |
| 69 | + $iterableFactory(), |
| 70 | + static fn (int $key, string $value) => new Pair($key * 2, $value . '_') |
| 71 | + ); |
| 72 | + |
| 73 | + self::assertCount(2, $map); |
| 74 | + |
| 75 | + $queueAt2 = $map->get(2); |
| 76 | + self::assertSame('a_', $queueAt2->pop()); |
| 77 | + self::assertSame('b_', $queueAt2->pop()); |
| 78 | + |
| 79 | + $queueAt4 = $map->get(4); |
| 80 | + self::assertSame('c_', $queueAt4->pop()); |
| 81 | + self::assertSame('d_', $queueAt4->pop()); |
| 82 | + } |
| 83 | + |
56 | 84 | public function testMappedSetsFromIterable(): void
|
57 | 85 | {
|
58 | 86 | /** @var callable():Generator<int, string> $iterableFactory */
|
|
0 commit comments