From 5125d5fef09fca764f84b3fdaff557d4d8b56acc Mon Sep 17 00:00:00 2001 From: Stephen Rees-Carter Date: Mon, 22 Jan 2024 04:02:32 +0100 Subject: [PATCH] Reduce failure rate of Arr::shuffle() tests (#49769) --- tests/Support/SupportArrTest.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index 160c440de74d..023157ba097b 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -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);