def test_search_with_7_strings(self):
     # Create a complete binary search tree of 7 items in level-order
     items = ['D', 'B', 'F', 'A', 'C', 'E', 'G']
     tree = BinarySearchTree(items)
     for item in items:
         assert tree.search(item) == item
     assert tree.search('H') is None
 def test_search_with_7_items(self):
     # Create a complete binary search tree of 7 items in level-order
     items = [4, 2, 6, 1, 3, 5, 7]
     tree = BinarySearchTree(items)
     for item in items:
         assert tree.search(item) == item
     assert tree.search(8) is None
 def test_search_with_3_strings(self):
     # Create a complete binary search tree of 3 items in level-order
     items = ['B', 'A', 'C']
     tree = BinarySearchTree(items)
     assert tree.search('A') == 'A'
     assert tree.search('B') == 'B'
     assert tree.search('C') == 'C'
     assert tree.search('D') is None
 def test_search_with_3_items(self):
     # Create a complete binary search tree of 3 items in level-order
     items = [2, 1, 3]
     tree = BinarySearchTree(items)
     assert tree.search(1) == 1
     assert tree.search(2) == 2
     assert tree.search(3) == 3
     assert tree.search(4) is None
    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])
    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_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)