diff options
author | Raymond Hettinger <python@rcn.com> | 2004-06-13 05:26:33 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-06-13 05:26:33 (GMT) |
commit | 2e3dfaf7070900c459d5879530dbdb3680f7fb9d (patch) | |
tree | c6d22113751862d95c53cd2a19fb42aa8d9f5b2c /Lib/test/test_heapq.py | |
parent | c929766361b4e0ea5bf5dc625e326fb954956f0b (diff) | |
download | cpython-2e3dfaf7070900c459d5879530dbdb3680f7fb9d.zip cpython-2e3dfaf7070900c459d5879530dbdb3680f7fb9d.tar.gz cpython-2e3dfaf7070900c459d5879530dbdb3680f7fb9d.tar.bz2 |
Install C version of heapq.nsmallest().
Diffstat (limited to 'Lib/test/test_heapq.py')
-rw-r--r-- | Lib/test/test_heapq.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py index 1cdaabe..b6fec9f 100644 --- a/Lib/test/test_heapq.py +++ b/Lib/test/test_heapq.py @@ -4,6 +4,7 @@ from heapq import heappush, heappop, heapify, heapreplace, nlargest, nsmallest import random import unittest from test import test_support +import sys def heapiter(heap): @@ -91,16 +92,28 @@ class TestHeap(unittest.TestCase): def test_nsmallest(self): data = [random.randrange(2000) for i in range(1000)] - self.assertEqual(nsmallest(data, 400), sorted(data)[:400]) - self.assertEqual(nsmallest(data, 50), sorted(data)[:50]) + for i in (0, 1, 2, 10, 100, 400, 999, 1000, 1100): + self.assertEqual(nsmallest(data, i), sorted(data)[:i]) def test_largest(self): data = [random.randrange(2000) for i in range(1000)] - self.assertEqual(nlargest(data, 400), sorted(data, reverse=True)[:400]) + for i in (0, 1, 2, 10, 100, 400, 999, 1000, 1100): + self.assertEqual(nlargest(data, i), sorted(data, reverse=True)[:i]) -def test_main(): - test_support.run_unittest(TestHeap) +def test_main(verbose=None): + test_classes = [TestHeap] + test_support.run_unittest(*test_classes) + + # verify reference counting + if verbose and hasattr(sys, "gettotalrefcount"): + import gc + counts = [None] * 5 + for i in xrange(len(counts)): + test_support.run_unittest(*test_classes) + gc.collect() + counts[i] = sys.gettotalrefcount() + print counts if __name__ == "__main__": - test_main() + test_main(verbose=True) |