Skip to content

Commit

Permalink
Reduce failure rate of Arr::shuffle() tests (laravel#49769)
Browse files Browse the repository at this point in the history
  • Loading branch information
valorin authored Jan 22, 2024
1 parent 1fe1280 commit 5125d5f
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions tests/Support/SupportArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,24 +907,34 @@ public function testSet()
$this->assertEquals([1 => 'hAz'], Arr::set($array, 1, 'hAz'));
}

public function testShuffle()
public function testShuffleProducesDifferentShuffles()
{
$input = ['a', 'b', 'c', 'd', 'e', 'f'];
$input = range('a', 'z');

$this->assertNotEquals(
$input,
Arr::shuffle($input)
$this->assertFalse(
Arr::shuffle($input) === Arr::shuffle($input) && Arr::shuffle($input) === Arr::shuffle($input),
"The shuffles produced the same output each time, which shouldn't happen."
);
}

public function testShuffleActuallyShuffles()
{
$input = range('a', 'z');

$this->assertFalse(
Arr::shuffle($input) === Arr::shuffle($input) && Arr::shuffle($input) === Arr::shuffle($input),
"The shuffles produced the same output each time, which shouldn't happen."
);

$this->assertNotEquals(
Arr::shuffle($input),
Arr::shuffle($input)
$this->assertFalse(
Arr::shuffle($input) === $input && Arr::shuffle($input) === $input,
"The shuffles were unshuffled each time, which shouldn't happen."
);
}

public function testShuffleKeepsSameValues()
{
$input = ['a', 'b', 'c', 'd', 'e', 'f'];
$input = range('a', 'z');
$shuffled = Arr::shuffle($input);
sort($shuffled);

Expand Down

0 comments on commit 5125d5f

Please sign in to comment.