[Python-checkins] python/dist/src/Lib/test test_heapq.py,1.6,1.7

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
2002年12月07日 02:33:45 -0800


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv26106
Modified Files:
	test_heapq.py 
Log Message:
Add another test which exercises the whole suite with a 
heapsort and verifies the result against list.sort().
Index: test_heapq.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_heapq.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** test_heapq.py	3 Aug 2002 10:10:10 -0000	1.6
--- test_heapq.py	7 Dec 2002 10:33:42 -0000	1.7
***************
*** 71,74 ****
--- 71,88 ----
 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:

AltStyle によって変換されたページ (->オリジナル) /