Exemplo n.º 1
0
def test__BST_remove_and_insert3(xs, ys):
    '''
    This test performs a mixture of both insertions and removals.
    This ensures that there are no weird interactions between inserting and removing.
    '''
    xs = list(set(xs))
    bst = BST(xs)
    for y in ys:
        bst.insert(y)
        x = bst.find_smallest()
        bst.remove(x)
        assert bst.is_bst_satisfied()
Exemplo n.º 2
0
def test__BST_remove2(xs):
    '''
    If we remove something from the BST that is not in the BST,
    then the BST should remain unchanged.
    '''
    xs = list(set(xs))
    bst = BST(xs)
    y = 0
    while y in xs:
        y += 1
    bst.remove(y)
    assert bst.to_list('inorder') == sorted(xs)
Exemplo n.º 3
0
def test__BST_remove_and_insert1(xs, ys):
    '''
    This test performs a mixture of both insertions and removals.
    This ensures that there are no weird interactions between inserting and removing.
    '''
    xs = list(set(xs))
    bst = BST(xs)
    for y in ys:
        bst.insert(y)
        x = random.choice(bst.to_list('inorder'))
        bst.remove(x)
        assert bst.is_bst_satisfied()
Exemplo n.º 4
0
def test__BST_remove1(xs):
    '''
    This tests the remove function.
    In order to test the remove function, we must be able to generate valid BSTs.
    Therefore, you must have all the insert functionality completed before this test can pass.
    '''
    xs = list(set(xs))
    bst = BST(xs)
    while len(xs) > 0:
        x = random.choice(xs)
        xs.remove(x)
        assert x in bst
        bst.remove(x)
        assert x not in bst
        assert bst.to_list('inorder') == sorted(xs)
        assert bst.is_bst_satisfied()