def test_removal(self): bst = BST() bst.insert(5) bst.insert(10) bst.insert(1) bst.insert(3) bst.insert(59) # remove leaf node bst.remove(3) inorder = bst.get_inorder() self.assertEqual(inorder, [5, 1, 10, 59]) self.assertEqual(bst.size, 4) # remove node with one child bst.remove(10) inorder = bst.get_inorder() self.assertEqual(inorder, [5, 1, 59]) self.assertEqual(bst.size, 3) bst.insert(3) bst.insert(4) bst.remove(5) inorder = bst.get_inorder() self.assertEqual(inorder, [4, 1, 3, 59]) self.assertEqual(bst.size, 4)
def test_inorder(self): bst = BST() bst.insert(5) bst.insert(10) bst.insert(1) bst.insert(3) bst.insert(59) inorder = bst.get_inorder() expected = [5, 1, 3, 10, 59] self.assertEqual(inorder, expected)