Skip to content

Commit

Permalink
Merge branch 'features/splay-tree-extra'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramy-Badr-Ahmed committed Oct 11, 2024
2 parents 1401b14 + 06aea18 commit 972b99d
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions tests/DataStructures/SplayTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,23 +464,13 @@ public function testDeleteMultipleKeys()
$splayTree = new SplayTree($arrayData);
$treeSize = $splayTree->size();

// pick randomly some nodes to delete
$randomNodesToDelete = array_rand($arrayData, rand(1, count($arrayData)));
$nodesToDelete = [150, 300, 50, 240, 170];
$expectedSize = $treeSize - count($nodesToDelete);

$randomNodesToDelete = is_array($randomNodesToDelete)
? $randomNodesToDelete
: [$randomNodesToDelete];

$expectedSize = $treeSize - count($randomNodesToDelete);

foreach ($randomNodesToDelete as $key) {
$isFound = $splayTree->isFound($key); // splay the key to the root before deletion
$this->assertTrue($isFound, "Node with key $key is not present for deletion.");

$rootKey = $splayTree->getRoot()->key;
$this->assertEquals($rootKey, $key, "Target key was not splayed to root correctly.");

$splayTree->delete($splayTree->getRoot()->key);
foreach ($nodesToDelete as $key) {
$splayTree->delete($key);
$isFound = $this->tree->isFound($key);
$this->assertFalse($isFound, "Node with key $key was not deleted.");
}

$this->assertEquals(
Expand Down

0 comments on commit 972b99d

Please sign in to comment.