From 5afe280143d617d276e3163219263efb5a7fe16b Mon Sep 17 00:00:00 2001 From: AlexandruGG <alex.gidei@goodlord.co> Date: Wed, 14 Jul 2021 23:33:27 +0100 Subject: [PATCH] Another example --- spec/loophp/collection/CollectionSpec.php | 35 ++++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/spec/loophp/collection/CollectionSpec.php b/spec/loophp/collection/CollectionSpec.php index a4ecbbd42..7b65c087b 100644 --- a/spec/loophp/collection/CollectionSpec.php +++ b/spec/loophp/collection/CollectionSpec.php @@ -2133,16 +2133,6 @@ public function it_can_merge(): void ->shouldIterateAs($generator()); } - public function it_reproduces_partition_issue(): void - { - $collection = $this::fromIterable([1, 2, 3, 4, 5]); - - [$even, $odd] = $collection->partition(static fn (int $value): bool => $value % 2 === 0)->all(); - - $even->shouldHaveCount(2); - $even->shouldIterateAs([1 => 2, 3 => 4]); - } - public function it_can_normalize(): void { $this::fromIterable(['a' => 10, 'b' => 100, 'c' => 1000]) @@ -3878,6 +3868,31 @@ public function it_is_initializable(): void $this->shouldHaveType(Collection::class); } + public function it_reproduces_partition_issue(): void + { + $collection = $this::fromIterable([1, 2, 3, 4, 5]); + + [$even, $odd] = $collection->partition(static fn (int $value): bool => $value % 2 === 0)->all(); + + $even->shouldHaveCount(2); + $even->shouldIterateAs([1 => 2, 3 => 4]); + } + + public function it_reproduces_partition_issue_using_first_last(): void + { + $collection = $this::fromIterable([1, 2, 3, 4, 5]); + + $partitioned = $collection->partition(static fn (int $value): bool => $value % 2 === 0); + $even = $partitioned->first()->current(); + + $even->shouldHaveCount(2); + $even->shouldIterateAs([1 => 2, 3 => 4]); + + $odd = $partitioned->last()->current(); + $odd->shouldHaveCount(3); + $odd->shouldIterateAs([0 => 1, 2 => 3, 4 => 5]); + } + public function let(): void { $this->beConstructedThrough('empty');