public function test_clearRemovesAllElements() { $tree = new BinaryTree(); $tree->insert(new types\NumericContainer(1)); $tree->clear(); $this->assertTrue($tree->isEmpty()); }
public function testSetRightTreeObject() { $obj_binaryTree = new BinaryTree('content'); $obj_binaryTree->setRightTree(null); $this->assertFalse($obj_binaryTree->isEmpty(), 'Binary tree should not be empty.'); $this->assertEquals('content', $obj_binaryTree->getObject(), 'Binary tree\'s object should equal content.'); $this->assertNotNull($obj_binaryTree->getLeftTree(), 'Left tree should not be null.'); $this->assertTrue($obj_binaryTree->getLeftTree()->isEmpty(), 'Left tree should be empty.'); $this->assertNotNull($obj_binaryTree->getRightTree(), 'Right tree should not be null.'); $this->assertTrue($obj_binaryTree->getRightTree()->isEmpty(), 'Right tree should be empty.'); $obj_binaryTree->setRightTree(new BinaryTree('content R')); $this->assertFalse($obj_binaryTree->isEmpty(), 'Binary tree should not be empty.'); $this->assertEquals('content', $obj_binaryTree->getObject(), 'Binary tree\'s object should equal content.'); $this->assertNotNull($obj_binaryTree->getLeftTree(), 'Left tree should not be null.'); $this->assertTrue($obj_binaryTree->getLeftTree()->isEmpty(), 'Left tree should be empty.'); $this->assertNotNull($obj_binaryTree->getRightTree(), 'Right tree should not be null.'); $this->assertFalse($obj_binaryTree->getRightTree()->isEmpty(), 'Right tree should not be empty.'); $this->assertEquals('content R', $obj_binaryTree->getRightTree()->getObject(), 'Right tree\'s object should equal content R.'); $obj_binaryTreeEmpty = new BinaryTree(); $obj_binaryTreeEmpty->setRightTree(new BinaryTree('content R')); $this->assertTrue($obj_binaryTreeEmpty->isEmpty(), 'Binary tree is empty.'); $this->assertNull($obj_binaryTreeEmpty->getObject(), 'Content should be null.'); $this->assertNull($obj_binaryTreeEmpty->getLeftTree(), 'Left tree should be null.'); $this->assertNull($obj_binaryTreeEmpty->getRightTree(), 'Right tree should be null.'); }