From 25b80d3fa15008a7959fc47abba877b860798ccd Mon Sep 17 00:00:00 2001 From: Ramy-Badr-Ahmed Date: Fri, 11 Oct 2024 15:52:58 +0200 Subject: [PATCH] Implementing Binary Search Tree as Data Structure. Fix if array_rand() returns non-array result --- tests/DataStructures/SplayTreeTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/DataStructures/SplayTreeTest.php b/tests/DataStructures/SplayTreeTest.php index 58ee287..0b3903a 100644 --- a/tests/DataStructures/SplayTreeTest.php +++ b/tests/DataStructures/SplayTreeTest.php @@ -463,10 +463,16 @@ public function testDeleteMultipleKeys() $splayTree = new SplayTree($arrayData); $treeSize = $splayTree->size(); + // pick randomly a number of nodes to delete within the arrayData $numberOfNodesToDelete = rand(1, count($arrayData)); + // pick randomly some nodes to delete by their keys $randomNodesToDelete = array_rand($arrayData, $numberOfNodesToDelete); + $randomNodesToDelete = is_array($randomNodesToDelete) + ? $randomNodesToDelete + : [$randomNodesToDelete]; + for ($i = 0; $i < count($randomNodesToDelete); $i++) { $splayTree->delete($randomNodesToDelete[$i]); $isFound = $splayTree->isFound($randomNodesToDelete[$i]);