Skip to content

Commit

Permalink
Another example
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandruGG committed Jul 14, 2021
1 parent 9eaf340 commit 5afe280
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 5afe280

Please sign in to comment.