summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_heapq.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2002-12-07 10:33:42 (GMT)
committerRaymond Hettinger <python@rcn.com>2002-12-07 10:33:42 (GMT)
commit065c06a6227d1c3f0a7cfa636c8e69b94a0e10d0 (patch)
tree86aa1ec8f607290c622aa7582eef2891daaac43f /Lib/test/test_heapq.py
parentc2e095f6f4bc7234442c704919429bfbe39b00c3 (diff)
downloadcpython-065c06a6227d1c3f0a7cfa636c8e69b94a0e10d0.zip
cpython-065c06a6227d1c3f0a7cfa636c8e69b94a0e10d0.tar.gz
cpython-065c06a6227d1c3f0a7cfa636c8e69b94a0e10d0.tar.bz2
Add another test which exercises the whole suite with a
heapsort and verifies the result against list.sort().
Diffstat (limited to 'Lib/test/test_heapq.py')
-rw-r--r--Lib/test/test_heapq.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py
index f0bb2e7..8f3c6f9 100644
--- a/Lib/test/test_heapq.py
+++ b/Lib/test/test_heapq.py
@@ -70,6 +70,20 @@ def test_main():
if item > heap[0]: # this gets rarer the longer we run
heapreplace(heap, item)
vereq(list(heapiter(heap)), data_sorted[-10:])
+ # 6) Exercise everything with repeated heapsort checks
+ for trial in xrange(100):
+ size = random.randrange(50)
+ data = [random.randrange(25) for i in range(size)]
+ if trial & 1: # Half of the time, use heapify
+ heap = data[:]
+ heapify(heap)
+ else: # The rest of the time, use heappush
+ heap = []
+ for item in data:
+ heappush(heap,item)
+ data.sort()
+ sorted = [heappop(heap) for i in range(size)]
+ vereq(data, sorted)
# Make user happy
if verbose:
print "All OK"