def test_get_top(self) -> None: """Test manipulation with the top (the smallest) item recorded.""" heap = ExtHeapQueue() heap.push(10.0, 10) assert heap.get_top() == 10 heap.push(-10.0, -10) assert heap.get_top() == -10 heap.push(100.0, 100) assert heap.get_top() == -10 heap.remove(100) assert heap.get_top() == -10 heap.remove(10) assert heap.get_top() == -10
def test_top_refcount(self) -> None: """Test manipulation with reference counter on get_top - compare with the standard heapq.""" heap = ExtHeapQueue() a, b = "foo_top", "bar_top" assert sys.getrefcount(a) == sys.getrefcount(b) heap.push(1.0, a) assert sys.getrefcount((a)) == sys.getrefcount(b) + 1 assert heap.get_top() == a assert sys.getrefcount((a)) == sys.getrefcount(b) + 1
def test_pushpop_refcount_saved(self) -> None: """Test manipulation with reference counter on pushpop - the item is stored in heap.""" heap = ExtHeapQueue() a1 = "zzzz" a2 = "fooo" heap.push(1.0, a1) assert heap.pushpop(0.1, a2) == a2 assert heap.get_top() == a1 assert heap.pop() == a1
def test_get_top_empty(self) -> None: """Test obtaining a top from an empty heap.""" heap = ExtHeapQueue() with pytest.raises(KeyError, match="the heap is empty"): heap.get_top() heap.push(1.0, 1) heap.remove(1) with pytest.raises(KeyError, match="the heap is empty"): heap.get_top() heap.push(1.0, 1) heap.pop() with pytest.raises(KeyError, match="the heap is empty"): heap.get_top()