예제 #1
0
def test__AVLTree_remove2(xs):
    '''
    If we remove something from the AVLTree that is not in the AVLTree,
    then the AVLTree should remain unchanged.
    '''
    xs = list(set(xs))
    avl = AVLTree(xs)
    y = 0
    while y in xs:
        y += 1
    avl.remove(y)
    assert avl.to_list('inorder') == sorted(xs)
예제 #2
0
def test__AVLTree_remove1(xs):
    '''
    This tests the remove function.
    In order to test the remove function, we must be able to generate valid AVLTrees.
    Therefore, you must have all the insert functionality completed before this test can pass.
    '''
    random.seed(0)
    xs = list(set(xs))
    avl = AVLTree(xs)
    while len(xs) > 0:
        x = random.choice(xs)
        xs.remove(x)
        assert x in avl
        avl.remove(x)
        assert x not in avl
        assert set(avl.to_list('inorder')) == set(xs)
        assert avl.is_avl_satisfied()