Пример #1
0
def test__Heap_insert_list(xs):
    xs = list(xs)
    heap = Heap()
    heap.insert_list(xs)
    assert heap.is_heap_satisfied()
    for x in xs:
        assert x in heap.to_list('inorder')
Пример #2
0
def test__Heap_is_heap_satisified1():
    heap = Heap()
    heap.root = Node(0)
    heap.root.left = Node(2)
    heap.root.left.left = Node(2)
    heap.root.left.right = Node(5)
    heap.root.right = Node(0)
    heap.root.right.left = Node(0)
    heap.root.right.right = Node(30)
    assert heap.is_heap_satisfied()
Пример #3
0
def test__Heap_is_heap_satisified6():
    heap = Heap()
    heap.root = Node(0)
    heap.root.left = Node(2)
    heap.root.left.left = Node(3)
    heap.root.left.right = Node(5)
    heap.root.right = Node(1)
    heap.root.right.left = Node(4)
    heap.root.right.right = Node(-1)
    assert not heap.is_heap_satisfied()
Пример #4
0
def test__Heap_remove_and_insert2(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(xs)
    heap = Heap(xs)
    for y in ys:
        heap.insert(y)
        heap.remove_min()
        assert heap.is_heap_satisfied()
Пример #5
0
def test__Heap_remove1(xs):
    '''
    This tests the remove function.
    In order to test the remove function, we must be able to generate valid Heaps.
    Therefore, you must have all the insert functionality completed before this test can pass.
    '''
    xs = list(xs)
    heap = Heap(xs)
    while len(xs)>0:
        x = min(xs)
        xs.remove(min(xs))
        assert x in heap.to_list('inorder')
        heap.remove_min()
        assert heap.is_heap_satisfied()
Пример #6
0
def test__Heap_is_heap_satisified4():
    heap = Heap()
    heap.root = Node(0)
    heap.root.left = Node(-1)
    assert not heap.is_heap_satisfied()
Пример #7
0
def test__Heap_is_heap_satisified3():
    heap = Heap()
    assert heap.is_heap_satisfied()
Пример #8
0
def test__Heap_is_heap_satisfied2():
    heap = Heap()
    heap.root = Node(-2)
    heap.root.left = Node(3)
    heap.root.right = Node(4)
    assert heap.is_heap_satisfied()