diff options
author | Raymond Hettinger <python@rcn.com> | 2004-06-10 05:03:17 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-06-10 05:03:17 (GMT) |
commit | 33ecffb65ae43ece95e4d828f95819395187d579 (patch) | |
tree | 499adce5b4fc964973a8e72baf2c6214bcef89e3 /Lib/test/test_heapq.py | |
parent | 7d019664d7fcd3692eafef668fbc2e17126dee14 (diff) | |
download | cpython-33ecffb65ae43ece95e4d828f95819395187d579.zip cpython-33ecffb65ae43ece95e4d828f95819395187d579.tar.gz cpython-33ecffb65ae43ece95e4d828f95819395187d579.tar.bz2 |
SF patch #969791: Add nlargest() and nsmallest() to heapq.
Diffstat (limited to 'Lib/test/test_heapq.py')
-rw-r--r-- | Lib/test/test_heapq.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py index 8f3c6f9..f04ea94 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, heapreplace +from heapq import heappush, heappop, heapify, heapreplace, nlargest, nsmallest import random def check_invariant(heap): @@ -84,6 +84,15 @@ def test_main(): data.sort() sorted = [heappop(heap) for i in range(size)] vereq(data, sorted) + + # 7) Check nlargest() and nsmallest() + data = [random.randrange(2000) for i in range(1000)] + copy = data[:] + copy.sort(reverse=True) + vereq(nlargest(data, 400), copy[:400]) + copy.sort() + vereq(nsmallest(data, 400), copy[:400]) + # Make user happy if verbose: print "All OK" |