mirror of
https://github.com/python/cpython.git
synced 2024-11-24 10:24:35 +08:00
Add another test which exercises the whole suite with a
heapsort and verifies the result against list.sort().
This commit is contained in:
parent
c2e095f6f4
commit
065c06a622
@ -70,6 +70,20 @@ def test_main():
|
|||||||
if item > heap[0]: # this gets rarer the longer we run
|
if item > heap[0]: # this gets rarer the longer we run
|
||||||
heapreplace(heap, item)
|
heapreplace(heap, item)
|
||||||
vereq(list(heapiter(heap)), data_sorted[-10:])
|
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
|
# Make user happy
|
||||||
if verbose:
|
if verbose:
|
||||||
print "All OK"
|
print "All OK"
|
||||||
|
Loading…
Reference in New Issue
Block a user