def test_H_graft_right(self): my_scion = bt.BinaryTree(preorder=['A', 'B', 'C', 'D'], inorder=['B', 'A', 'C', 'D']) resultant_tree = bt.BinaryTree( preorder=[4, 7, 2, 1, 'A', 'B', 'C', 'D', 8, 3, 5], inorder=[2, 7, 1, 'B', 'A', 'C', 'D', 4, 8, 5, 3]) self.tree.graft(self.tree.root.left.right, my_scion, right=True) self.assertEqual(self.tree, resultant_tree)
def test_F_insert_right(self): resultant_tree = bt.BinaryTree(preorder=[4, 7, 2, 1, 9, 8, 3, 5], inorder=[2, 7, 1, 9, 4, 8, 5, 3]) self.tree.insert(9, parent=self.tree.root.left.right, right=True) self.assertEqual(self.tree, resultant_tree)
def test_D_invert(self): resultant_tree = bt.BinaryTree(preorder=[4, 8, 3, 5, 7, 1, 2], inorder=[3, 5, 8, 4, 1, 7, 2]) self.tree.traverse(self.tree.invert) self.assertEqual(self.tree, resultant_tree)
def test_5_remove(self): resultant_tree = bt.BinaryTree(preorder=[4, 7, 2, 1, 3, 5], inorder=[2, 7, 1, 4, 5, 3]) self.tree.remove(self.tree.root.right) self.assertEqual(self.tree, resultant_tree)
def setUp(self): self.tree = bt.BinaryTree(preorder=self.__class__.my_preorder, inorder=self.__class__.my_inorder)
def test_I_prune(self): resultant_tree = bt.BinaryTree(preorder=[4, 7, 2, 1], inorder=[2, 7, 1, 4]) self.tree.prune(self.tree.root.right) self.assertEqual(self.tree, resultant_tree)