Skip to content

Commit

Permalink
Implemented Binary Search Tree Data Structure with Iterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramy-Badr-Ahmed committed Oct 13, 2024
1 parent b595461 commit c7d9977
Showing 1 changed file with 0 additions and 85 deletions.
85 changes: 0 additions & 85 deletions tests/DataStructures/BSTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,89 +571,4 @@ public function testIteratorWithTraversalTypes(string $traversalType, array $exp
}
$this->assertEquals(count($expected), $index, "Tree iteration did not visit the expected number of nodes.");
}

/**
* Test: Iterating over the tree (default In-Order)
*/
public function testIteratorInOrder(): void
{
$expectedInOrder = $this->getExpectedInOrder();

$expectedKeys = array_keys($expectedInOrder);
$expectedValues = array_values($expectedInOrder);

$index = 0;

foreach ($this->tree as $node) {
$this->assertEquals(
$expectedKeys[$index],
$node->key,
"Did not match the expected inOrder key. Failed tree iteration."
);
$this->assertEquals(
$expectedValues[$index],
$node->value,
"Did not match the expected inOrder value. Failed tree iteration."
);
$index++;
}
}

/**
* Test: Iterating over the tree with Pre-Order traversal
*/
public function testIteratorPreOrder(): void
{
$this->tree = new BSTree([], 'preOrder');

$expectedPreOrder = $this->getExpectedPreOrder();

$expectedKeys = array_keys($expectedPreOrder);
$expectedValues = array_values($expectedPreOrder);

$index = 0;

foreach ($this->tree as $node) {
$this->assertEquals(
$expectedKeys[$index],
$node->key,
"Did not match the expected preOrder key. Failed tree iteration."
);
$this->assertEquals(
$expectedValues[$index],
$node->value,
"Did not match the expected preOrder value. Failed tree iteration."
);
$index++;
}
}

/**
* Test: Iterating over the tree with Post-Order traversal
*/
public function testIteratorPostOrder(): void
{
$this->tree->setTraversalType('postOrder');

$expectedPostOrder = $this->getExpectedPostOrder();

$expectedKeys = array_keys($expectedPostOrder);
$expectedValues = array_values($expectedPostOrder);

$index = 0;

foreach ($this->tree as $node) {
$this->assertEquals(
$expectedKeys[$index],
$node->key,
"Did not match the expected inOrder key. Failed tree iteration."
);
$this->assertEquals(
$expectedValues[$index],
$node->value,
"Did not match the expected inOrder value. Failed tree iteration."
);
$index++;
}
}
}

0 comments on commit c7d9977

Please sign in to comment.