def test_items_in_order(self): # Create a complete binary search tree of 7 items in level-order items = [4, 2, 6, 1, 3, 5, 7] bst = BinarySearchTree(items) assert bst.items_in_order() == [1, 2, 3, 4, 5, 6, 7]
def tree_sort(array): tree = BinarySearchTree(array) # O(n*log(n)) return tree.items_in_order()
def tree_sort(elements): bst = BinarySearchTree(elements) return bst.items_in_order()
def test_insert_with_repeated_items(self): items = [1, 2, 2] bst = BinarySearchTree(items) assert bst.search(2)[0] == 2 assert bst.items_in_order() == [1, 2, 2]
def test_items_in_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 in-order traversal of tree items is ordered correctly assert tree.items_in_order() == [1, 2, 3, 4, 5, 6, 7]
def test_items_in_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 in-order traversal of tree items is ordered correctly assert tree.items_in_order() == ['A', 'B', 'C']