Esempio n. 1
0
def test_pop():
    """Test if entry sorts to the correct position."""
    from binheap import Heap
    heap = Heap()
    heap.container = [2, 3, 4, 10]
    heap.pop()
    assert heap.container == [10, 3, 4]
Esempio n. 2
0
def test_push():
    """Test when a value is appended to the heap the structure is maintained."""
    from binheap import Heap
    heap = Heap()
    heap.container = [4, 7, 38, 96]
    heap.push(5)
    assert heap.container == [96, 7, 38, 4, 5]
Esempio n. 3
0
def test_pop_all_nodes():
    """."""
    from binheap import Heap
    heap = Heap()
    test_list = [97, 12, 13, 55, 108]
    temp_list = []
    for i in test_list:
        heap.push(i)
    for i in test_list:
        temp_list.append(heap.pop())
    assert temp_list == [108, 97, 55, 13, 12]
Esempio n. 4
0
def test_pop():
    """."""
    from binheap import Heap
    heap = Heap()
    heap.push(1)
    heap.push(2)
    heap.push(3)
    assert heap.pop() == 3
Esempio n. 5
0
def test_bubble_up_small():
    """."""
    from binheap import Heap
    heap = Heap()
    heap.push(2)
    heap.push(1)
    heap.push(3)
    assert heap.heap_list == [3, 1, 2]
Esempio n. 6
0
def binheap_fixture():
    """Fixture for the binary heap data structure."""
    from binheap import Heap
    return Heap()
Esempio n. 7
0
def binheap_full_unsorted():
    """A unsorted binheap."""
    from binheap import Heap
    binheap = Heap()
    binheap.push(-2)
    binheap.push(8)
    binheap.push(6)
    binheap.push(11)
    binheap.push(7)
    binheap.push(4)
    binheap.push(-1)
    binheap.push(5)
    binheap.push(0)
    binheap.push(10)
    binheap.push(3)
    binheap.push(12)
    binheap.push(9)
    binheap.push(1)
    binheap.push(2)
    return binheap
Esempio n. 8
0
def heap_3():
    """Create instance of heap with empty list."""
    from binheap import Heap
    test_heap = Heap([5, 99, 74])
    return test_heap
Esempio n. 9
0
def heap_2():
    """Create instance of heap with two values."""
    from binheap import Heap
    test_heap = Heap([7, 49])
    return test_heap
Esempio n. 10
0
def test_heap_of_10_nums_sorted_on_initialization():
    """Test to ensure heapify method is sorting correctly."""
    from binheap import Heap
    heap_10 = Heap([3, 22, 31, 4, 49, 47, 19, 88, 92, 2])
    assert heap_10.contents == [92, 88, 47, 49, 4, 22, 19, 3, 31, 2]