Esempio n. 1
0
def test__BST_insert(xs):
    xs = list(set(xs))
    bst = BST()
    for x in xs:
        bst.insert(x)
        assert x in bst.to_list('inorder')
        assert bst.is_bst_satisfied()
Esempio n. 2
0
def test__BST_is_bst_satisified5():
    bst = BST()
    bst.root = Node(0)
    bst.root.left = Node(-2)
    bst.root.left.left = Node(-3)
    bst.root.left.right = Node(-1)
    bst.root.right = Node(2)
    bst.root.right.left = Node(1)
    bst.root.right.right = Node(3)
    assert bst.is_bst_satisfied()
Esempio n. 3
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()
Esempio n. 4
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()
Esempio n. 5
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()
Esempio n. 6
0
def test__BST___init__(xs):
    xs = list(set(xs))
    bst = BST(xs)
    assert bst.is_bst_satisfied()
Esempio n. 7
0
def test__BST_insert_list(xs):
    xs = list(set(xs))
    bst = BST()
    bst.insert_list(xs)
    assert bst.is_bst_satisfied()
Esempio n. 8
0
def test__BST_is_bst_satisified4():
    bst = BST()
    bst.root = Node(0)
    bst.root.left = Node(-1)
    assert bst.is_bst_satisfied()
Esempio n. 9
0
def test__BST_is_bst_satisified3():
    bst = BST()
    assert bst.is_bst_satisfied()
Esempio n. 10
0
def test__BST_is_bst_satisfied2():
    bst = BST()
    bst.root = Node(-2)
    bst.root.left = Node(-3)
    bst.root.right = Node(-4)
    assert not bst.is_bst_satisfied()