Exemple #1
0
def test_best_case_insertion_sort():
    data = gen_sorted_array()
    sorted_data = SortedList(data)

    insertion_sort(data)

    assert np.array_equal(data, sorted_data)
Exemple #2
0
def test_worst_case_quick_sort():
    data = gen_sorted_array()
    sorted_data = SortedList(data)

    quick_sort(data, 0, len(data) - 1)

    assert np.array_equal(data, sorted_data)
Exemple #3
0
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)
Exemple #4
0
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
Exemple #5
0
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)
Exemple #6
0
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)