Skip to content

Commit

Permalink
Add tests for Random operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jul 27, 2020
1 parent 8b94f6d commit c71549c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,29 @@ public function it_can_prepend(): void
->shouldIterateAs($generator());
}

public function it_can_random(): void
{
$input = range('a', 'z');

$generator = static function (array $input): Generator {
yield from $input;
};

$this::fromIterable($input)
->random()
->count()
->shouldBeEqualTo(1);

$this::fromIterable($input)
->random(100)
->count()
->shouldBeEqualTo(26);

$this::fromIterable($input)
->random(26)
->shouldNotIterateAs($generator($input));
}

public function it_can_reduce(): void
{
$this::fromIterable(range(1, 100))
Expand Down

0 comments on commit c71549c

Please sign in to comment.