Esempio n. 1
0
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)
Esempio n. 2
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)
Esempio n. 3
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
Esempio n. 4
0
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
Esempio n. 5
0
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()
Esempio n. 6
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)
Esempio n. 7
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)