diff options
author | Tim Peters <tim.peters@gmail.com> | 2002-08-03 10:10:10 +0000 |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2002-08-03 10:10:10 +0000 |
commit | 0cd53a6c37347800f786c4ddaa2e91af30350b5a (patch) | |
tree | ae92812f3269876a3aec224f6374be09b19cbc27 /Lib/test/test_heapq.py | |
parent | 657fe38241a7f072bdbf040a7bd05df96f326c5c (diff) | |
download | cpython-git-0cd53a6c37347800f786c4ddaa2e91af30350b5a.tar.gz |
Added new heapreplace(heap, item) function, to pop (and return) the
currently-smallest value, and add item, in one gulp. See the second
N-Best algorithm in the test suite for a natural use.
Diffstat (limited to 'Lib/test/test_heapq.py')
-rw-r--r-- | Lib/test/test_heapq.py | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py index 7f6d918b51..f0bb2e7d1b 100644 --- a/Lib/test/test_heapq.py +++ b/Lib/test/test_heapq.py @@ -2,7 +2,7 @@ from test.test_support import verify, vereq, verbose, TestFailed -from heapq import heappush, heappop, heapify +from heapq import heappush, heappop, heapify, heapreplace import random def check_invariant(heap): @@ -68,8 +68,7 @@ def test_main(): heapify(heap) for item in data[10:]: if item > heap[0]: # this gets rarer the longer we run - heappop(heap) # we know heap[0] isn't in best 10 anymore - heappush(heap, item) + heapreplace(heap, item) vereq(list(heapiter(heap)), data_sorted[-10:]) # Make user happy if verbose: |