def test_search_root_value(self): bt = BinarySearchTree() bt.insert_multiple_values([10, 20, 22, 3, 7, 4, 32, 900]) node, depth = bt.search(10) self.assertEqual(node.value, 10) self.assertEqual(depth, 0)
def test_search_third_use_case(self): bt = BinarySearchTree() bt.insert_multiple_values([10, 20, 22, 3, 7, 4, 32, 900]) node, depth = bt.search(4) self.assertEqual(node.value, 4) self.assertEqual(depth, 3)
def test_structure(self): bt = BinarySearchTree() bt.insert_multiple_values([10, 20, 22, 3, 7, 4, 32, 900]) self.assertEqual(bt.root.value, 10) self.assertEqual(bt.root.left.value, 3) self.assertEqual(bt.root.left.right.value, 7) self.assertEqual(bt.root.left.right.left.value, 4)
def test_deletion_leaf(self): bt = BinarySearchTree() bt.insert_multiple_values([10, 20, 22, 3, 7, 4, 32, 900]) node, depth = bt.search(900) self.assertEqual(node.value, 900) self.assertEqual(depth, 4) bt.delete(900) node, _ = bt.search(900) self.assertIsNone(node) self.assertEqual(bt.in_order(), [3, 4, 7, 10, 20, 22, 32])
def test_deletion_first_use_case(self): bt = BinarySearchTree() bt.insert_multiple_values([10, 20, 22, 3, 7, 4, 32, 900]) node, depth = bt.search(4) self.assertEqual(node.value, 4) self.assertEqual(depth, 3) bt.delete(4) node, depth = bt.search(4) self.assertIsNone(node) self.assertEqual(bt.in_order(), [3, 7, 10, 20, 22, 32, 900])