def main(): # creating a binary search tree data = [17, 13, 10, 15, 4, 11, 16, 21, 24, 23, 27, 25, 26] bst = BinarySearchTree(data) print(bst.breadth_first_list()) # Removing a few items... print('\nDeleting a few items...') bst.remove(4) bst.remove(10) bst.remove(27) bst.remove(13) print(bst.breadth_first_list()) print("\nadding 45 to BST...") bst.add(45) print(bst.breadth_first_list()) print('\nTHe height of the tree :', bst.height) print('\nBST contains 45:', bst.contains(45))
def test_contains(self): binary_search_tree = BinarySearchTree() binary_search_tree.add(50) binary_search_tree.add(100) binary_search_tree.add(0) binary_search_tree.add(75) binary_search_tree.add(25) binary_search_tree.add(88) binary_search_tree.add(33) binary_search_tree.add(66) binary_search_tree.add(11) assert (binary_search_tree.contains(50) is True) assert (binary_search_tree.contains(100) is True) assert (binary_search_tree.contains(0) is True) assert (binary_search_tree.contains(75) is True) assert (binary_search_tree.contains(25) is True) assert (binary_search_tree.contains(88) is True) assert (binary_search_tree.contains(33) is True) assert (binary_search_tree.contains(66) is True) assert (binary_search_tree.contains(11) is True) assert (binary_search_tree.contains(99) is False)
def test_contains(): bst = BinarySearchTree([5, 7, 3]) assert bst.contains(5) == True assert bst.contains(99) == False