def test_get_size_returns_size_of_heap(): heap = Heap(5, default_priority_function) heap.insert(1) heap.insert(5) heap.insert(6) heap.insert(2) result = heap.get_size() assert result == 4 heap.extract() result = heap.get_size() assert result == 3
def test_balance_heaps_balanced_an_imbalanced_pair_of_heaps(): min_heap = Heap(10, max_priority_function) max_heap = Heap(10, min_priority_function) min_heap.insert(1) min_heap.insert(3) min_heap.insert(2) min_heap.insert(4) max_heap.insert(7) max_heap.insert(5) sut = RunningMedian() sut.balance_heaps(min_heap, max_heap) assert min_heap.get_size() == 3 assert max_heap.get_size() == 3 assert 4 in max_heap.items assert 4 not in min_heap.items
def test_delete_removes_target_item_from_heap(): heap = Heap(5) heap.insert(1) heap.insert(3) heap.insert(2) heap.insert(4) heap.delete(3) assert heap.get_size() == 3 assert heap.extract() == 4 assert heap.extract() == 2
def test_extract_and_insert_alternating_returns_values(): heap = Heap(5, default_priority_function) heap.insert(1) heap.insert(5) assert heap.extract() == 5 heap.insert(6) heap.insert(2) assert heap.extract() == 6 heap.insert(6) assert heap.extract() == 6 heap.insert(10) heap.insert(1) assert heap.get_size() == 4