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_insert_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() for item in items: tree.insert(item) assert tree.root.data == 4
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_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_size(self): tree = BinarySearchTree() assert tree.size == 0 tree.insert('B') assert tree.size == 1 tree.insert('A') assert tree.size == 2 tree.insert('C') assert tree.size == 3
def test_insert_with_3_items(self): # Create a complete binary search tree of 3 items in level-order tree = BinarySearchTree() tree.insert(2) assert tree.root.data == 2 tree.insert(1) assert tree.root.data == 2 tree.insert(3) assert tree.root.data == 2
def DISABLED_test_delete_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.root.data == 2
def test_init(self): tree = BinarySearchTree() assert tree.root is None assert tree.size == 0 assert tree.is_empty() is True
def test_init_with_list_of_tuples(self): tree = BinarySearchTree([(2, 'B'), (1, 'A'), (3, 'C')]) assert tree.root.data == (2, 'B') assert tree.size == 3 assert tree.is_empty() is False
def test_init_with_list_of_strings(self): tree = BinarySearchTree(['B', 'A', 'C']) assert tree.root.data == 'B' assert tree.size == 3 assert tree.is_empty() is False
def test_items_level_order_with_7_numbers(self): # Create a complete binary search tree of 7 items in level-order items = [4, 2, 6, 1, 3, 5, 7] tree = BinarySearchTree(items) # Ensure the level-order traversal of tree items is ordered correctly assert tree.items_level_order() == [4, 2, 6, 1, 3, 5, 7]
def test_items_level_order_with_3_strings(self): # Create a complete binary search tree of 3 strings in level-order items = ['B', 'A', 'C'] tree = BinarySearchTree(items) # Ensure the level-order traversal of tree items is ordered correctly assert tree.items_level_order() == ['B', 'A', 'C']
def test_init_with_list(self): tree = BinarySearchTree([2, 1, 3]) assert tree.root.data == 2 assert tree.size == 3 assert tree.is_empty() is False
def DISABLED_test_delete_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)