def test_get_last_empty(self) -> None: """Test obtaining a last item from an empty heap produces an exception.""" heap = ExtHeapQueue() with pytest.raises(KeyError, match="the heap is empty"): heap.get_last() heap.push(1.0, 1) heap.remove(1) with pytest.raises(KeyError, match="the heap is empty"): heap.get_last() heap.push(1.0, 1) heap.pop() with pytest.raises(KeyError, match="the heap is empty"): heap.get_max()
def test_last_refcount(self) -> None: """Test manipulation with reference counter on last - compare with the standard heapq.""" heap = ExtHeapQueue() a, b = "foo_last", "bar_last" assert sys.getrefcount(a) == sys.getrefcount(b) heap.push(1.0, a) assert sys.getrefcount(a) == sys.getrefcount(b) + 1 assert heap.get_last() == a assert sys.getrefcount(a) == sys.getrefcount(b) + 1
def test_get_last(self) -> None: """Test obtaining a last item from a heap.""" heap = ExtHeapQueue() heap.push(6.0, 6) assert heap.get_last() == 6 heap.push(3.0, 3) assert heap.get_last() == 3 heap.remove(3) assert heap.get_last() is None heap.push(8.0, 8) assert heap.get_last() == 8 heap.pop() assert heap.get_last() is 8 assert len(heap) == 1 heap.pop() assert len(heap) == 0