[Python-checkins] python/dist/src/Lib/test test_heapq.py,1.16,1.17

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Thu Dec 2 09:59:16 CET 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20862/Lib/test
Modified Files:
	test_heapq.py 
Log Message:
Add key= argument to heapq.nsmallest() and heapq.nlargest().
Index: test_heapq.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_heapq.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- test_heapq.py	29 Nov 2004 05:54:48 -0000	1.16
+++ test_heapq.py	2 Dec 2004 08:59:14 -0000	1.17
@@ -105,13 +105,19 @@
 
 def test_nsmallest(self):
 data = [random.randrange(2000) for i in range(1000)]
+ f = lambda x: x * 547 % 2000
 for n in (0, 1, 2, 10, 100, 400, 999, 1000, 1100):
 self.assertEqual(nsmallest(n, data), sorted(data)[:n])
+ self.assertEqual(nsmallest(n, data, key=f),
+ sorted(data, key=f)[:n])
 
- def test_largest(self):
+ def test_nlargest(self):
 data = [random.randrange(2000) for i in range(1000)]
+ f = lambda x: x * 547 % 2000
 for n in (0, 1, 2, 10, 100, 400, 999, 1000, 1100):
 self.assertEqual(nlargest(n, data), sorted(data, reverse=True)[:n])
+ self.assertEqual(nlargest(n, data, key=f),
+ sorted(data, key=f, reverse=True)[:n])
 
 
 #==============================================================================


More information about the Python-checkins mailing list

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