diff options
author | Raymond Hettinger <python@rcn.com> | 2004-12-02 08:59:14 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-12-02 08:59:14 (GMT) |
commit | 4901a1f267e9d632f85054ce8b21ff23bff305e1 (patch) | |
tree | 27fdb176c85c194cc32d9a72d4812860bd2c4fb6 /Lib/test | |
parent | de7b99045d6ee40c2f6b0abbf9d1b5345d9cf15e (diff) | |
download | cpython-4901a1f267e9d632f85054ce8b21ff23bff305e1.zip cpython-4901a1f267e9d632f85054ce8b21ff23bff305e1.tar.gz cpython-4901a1f267e9d632f85054ce8b21ff23bff305e1.tar.bz2 |
Add key= argument to heapq.nsmallest() and heapq.nlargest().
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_heapq.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py index 68003e7..2da4f8c 100644 --- a/Lib/test/test_heapq.py +++ b/Lib/test/test_heapq.py @@ -105,13 +105,19 @@ class TestHeap(unittest.TestCase): 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]) #============================================================================== |