summaryrefslogtreecommitdiff
path: root/Lib/test/test_heapq.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-06-10 05:03:17 +0000
committerRaymond Hettinger <python@rcn.com>2004-06-10 05:03:17 +0000
commit33ecffb65ae43ece95e4d828f95819395187d579 (patch)
tree499adce5b4fc964973a8e72baf2c6214bcef89e3 /Lib/test/test_heapq.py
parent7d019664d7fcd3692eafef668fbc2e17126dee14 (diff)
downloadcpython-git-33ecffb65ae43ece95e4d828f95819395187d579.tar.gz
SF patch #969791: Add nlargest() and nsmallest() to heapq.
Diffstat (limited to 'Lib/test/test_heapq.py')
-rw-r--r--Lib/test/test_heapq.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py
index 8f3c6f9ac9..f04ea9452f 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"