def test_avg_case_insertion_sort(): data = gen_random_u_array() sorted_data = SortedList(data) insertion_sort(data) assert np.array_equal(data, sorted_data)
def test_avg_case_quick_sort(): data = gen_random_u_array() sorted_data = SortedList(data) quick_sort(data, 0, len(data) - 1) assert np.array_equal(data, sorted_data)
def test_postorder(): bst = BinarySearchTree() rbt = RedBlackTree() data = gen_random_u_array(10) for d in data: bst.insert(d) rbt.insert(d) assert np.array_equal(bst.postorder(), rbt.postorder()) is False
def test_maximum(): bst = BinarySearchTree() rbt = RedBlackTree() data = gen_random_u_array(10) for d in data: bst.insert(d) rbt.insert(d) assert bst.maximum().key is rbt.maximum().key
def test_tree_height(): bst = BinarySearchTree() rbt = RedBlackTree() data = gen_random_u_array() for d in data: bst.insert(d) rbt.insert(d) assert bst.tree_height() is not rbt.tree_height()
def test_insertion_rn(): data = gen_random_u_array() sorted_data = SortedList(data) rbt = RedBlackTree() for d in data: rbt.insert(d) assert np.array_equal(rbt.inorder(), sorted_data)
def test_insertion_bst(): data = gen_random_u_array() sorted_data = SortedList(data) bst = BinarySearchTree() for d in data: bst.insert(d) assert np.array_equal(bst.inorder(), sorted_data)