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]
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]
def test_pop(): """.""" from binheap import Heap heap = Heap() heap.push(1) heap.push(2) heap.push(3) assert heap.pop() == 3
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]
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