Skip to content

Commit

Permalink
Implemented Splay Tree Data Structure. Added test for large splay tre…
Browse files Browse the repository at this point in the history
…e operations.
  • Loading branch information
Ramy-Badr-Ahmed committed Oct 12, 2024
1 parent 06aea18 commit f6b93b0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/DataStructures/SplayTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,28 @@ public function testOperationsOnEmptyTree()
$this->assertNull($rootNode4, "Deleting a key in an empty tree should return null.");
}

/**
* Test insert, search, delete on large trees
*/
public function testLargeTree(): void
{
// Inserting a large number of nodes
for ($i = 1; $i <= 1000; $i++) {
$this->tree->insert($i, "Value $i");
}

// Verify that all inserted nodes can be searched
for ($i = 1; $i <= 1000; $i++) {
$this->assertEquals("Value $i", $this->tree->search($i)->value, "Value for key $i should be 'Value $i'");
}

// Verify that all inserted nodes can be deleted
for ($i = 1; $i <= 5; $i++) {
$this->tree->delete($i);
$this->assertFalse($this->tree->isFound($i), "Node was not deleted correctly");
}
}


// ------------- Test 6 Rotation types of the Splay Tree -------------

Expand Down

0 comments on commit f6b93b0

Please sign in to comment.