Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_bisect.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 82ccc7e77ec5 |
| children | 6768b2350c57 |
| rev | line source |
|---|---|
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
1 import sys |
|
27266
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
2 import unittest |
|
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
3 from test import test_support |
|
31353
ed20259a1ea5
SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
4 from UserList import UserList |
|
27266
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
5 |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
6 # We do a bit of trickery here to be able to test both the C implementation |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
7 # and the Python implementation of the module. |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
8 |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
9 # Make it impossible to import the C implementation anymore. |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
10 sys.modules['_bisect'] = 0 |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
11 # We must also handle the case that bisect was imported before. |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
12 if 'bisect' in sys.modules: |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
13 del sys.modules['bisect'] |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
14 |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
15 # Now we can import the module and get the pure Python implementation. |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
16 import bisect as py_bisect |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
17 |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
18 # Restore everything to normal. |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
19 del sys.modules['_bisect'] |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
20 del sys.modules['bisect'] |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
21 |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
22 # This is now the module with the C implementation. |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
23 import bisect as c_bisect |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
24 |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
25 |
|
27266
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
26 class TestBisect(unittest.TestCase): |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
27 module = None |
|
27266
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
28 |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
29 def setUp(self): |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
30 self.precomputedCases = [ |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
31 (self.module.bisect_right, [], 1, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
32 (self.module.bisect_right, [1], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
33 (self.module.bisect_right, [1], 1, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
34 (self.module.bisect_right, [1], 2, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
35 (self.module.bisect_right, [1, 1], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
36 (self.module.bisect_right, [1, 1], 1, 2), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
37 (self.module.bisect_right, [1, 1], 2, 2), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
38 (self.module.bisect_right, [1, 1, 1], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
39 (self.module.bisect_right, [1, 1, 1], 1, 3), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
40 (self.module.bisect_right, [1, 1, 1], 2, 3), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
41 (self.module.bisect_right, [1, 1, 1, 1], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
42 (self.module.bisect_right, [1, 1, 1, 1], 1, 4), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
43 (self.module.bisect_right, [1, 1, 1, 1], 2, 4), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
44 (self.module.bisect_right, [1, 2], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
45 (self.module.bisect_right, [1, 2], 1, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
46 (self.module.bisect_right, [1, 2], 1.5, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
47 (self.module.bisect_right, [1, 2], 2, 2), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
48 (self.module.bisect_right, [1, 2], 3, 2), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
49 (self.module.bisect_right, [1, 1, 2, 2], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
50 (self.module.bisect_right, [1, 1, 2, 2], 1, 2), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
51 (self.module.bisect_right, [1, 1, 2, 2], 1.5, 2), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
52 (self.module.bisect_right, [1, 1, 2, 2], 2, 4), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
53 (self.module.bisect_right, [1, 1, 2, 2], 3, 4), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
54 (self.module.bisect_right, [1, 2, 3], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
55 (self.module.bisect_right, [1, 2, 3], 1, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
56 (self.module.bisect_right, [1, 2, 3], 1.5, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
57 (self.module.bisect_right, [1, 2, 3], 2, 2), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
58 (self.module.bisect_right, [1, 2, 3], 2.5, 2), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
59 (self.module.bisect_right, [1, 2, 3], 3, 3), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
60 (self.module.bisect_right, [1, 2, 3], 4, 3), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
61 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
62 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
63 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1.5, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
64 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2, 3), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
65 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2.5, 3), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
66 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3, 6), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
67 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3.5, 6), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
68 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 4, 10), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
69 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 5, 10), |
|
15673
67b3ac439f64
Fred, THIS NEEDS DOCS! The function docstrings tell the tale.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
70 |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
71 (self.module.bisect_left, [], 1, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
72 (self.module.bisect_left, [1], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
73 (self.module.bisect_left, [1], 1, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
74 (self.module.bisect_left, [1], 2, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
75 (self.module.bisect_left, [1, 1], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
76 (self.module.bisect_left, [1, 1], 1, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
77 (self.module.bisect_left, [1, 1], 2, 2), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
78 (self.module.bisect_left, [1, 1, 1], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
79 (self.module.bisect_left, [1, 1, 1], 1, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
80 (self.module.bisect_left, [1, 1, 1], 2, 3), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
81 (self.module.bisect_left, [1, 1, 1, 1], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
82 (self.module.bisect_left, [1, 1, 1, 1], 1, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
83 (self.module.bisect_left, [1, 1, 1, 1], 2, 4), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
84 (self.module.bisect_left, [1, 2], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
85 (self.module.bisect_left, [1, 2], 1, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
86 (self.module.bisect_left, [1, 2], 1.5, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
87 (self.module.bisect_left, [1, 2], 2, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
88 (self.module.bisect_left, [1, 2], 3, 2), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
89 (self.module.bisect_left, [1, 1, 2, 2], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
90 (self.module.bisect_left, [1, 1, 2, 2], 1, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
91 (self.module.bisect_left, [1, 1, 2, 2], 1.5, 2), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
92 (self.module.bisect_left, [1, 1, 2, 2], 2, 2), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
93 (self.module.bisect_left, [1, 1, 2, 2], 3, 4), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
94 (self.module.bisect_left, [1, 2, 3], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
95 (self.module.bisect_left, [1, 2, 3], 1, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
96 (self.module.bisect_left, [1, 2, 3], 1.5, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
97 (self.module.bisect_left, [1, 2, 3], 2, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
98 (self.module.bisect_left, [1, 2, 3], 2.5, 2), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
99 (self.module.bisect_left, [1, 2, 3], 3, 2), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
100 (self.module.bisect_left, [1, 2, 3], 4, 3), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
101 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 0, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
102 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1, 0), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
103 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1.5, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
104 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2, 1), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
105 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2.5, 3), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
106 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3, 3), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
107 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3.5, 6), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
108 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 4, 6), |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
109 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 5, 10) |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
110 ] |
|
15673
67b3ac439f64
Fred, THIS NEEDS DOCS! The function docstrings tell the tale.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
111 |
|
27266
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
112 def test_precomputed(self): |
|
27269
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
113 for func, data, elem, expected in self.precomputedCases: |
|
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
114 self.assertEqual(func(data, elem), expected) |
|
31353
ed20259a1ea5
SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
115 self.assertEqual(func(UserList(data), elem), expected) |
|
27266
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
116 |
|
47919
8e7383cbe56e
Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents:
45484
diff
changeset
|
117 def test_negative_lo(self): |
|
8e7383cbe56e
Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents:
45484
diff
changeset
|
118 # Issue 3301 |
|
8e7383cbe56e
Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents:
45484
diff
changeset
|
119 mod = self.module |
|
8e7383cbe56e
Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents:
45484
diff
changeset
|
120 self.assertRaises(ValueError, mod.bisect_left, [1, 2, 3], 5, -1, 3), |
|
8e7383cbe56e
Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents:
45484
diff
changeset
|
121 self.assertRaises(ValueError, mod.bisect_right, [1, 2, 3], 5, -1, 3), |
|
8e7383cbe56e
Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents:
45484
diff
changeset
|
122 self.assertRaises(ValueError, mod.insort_left, [1, 2, 3], 5, -1, 3), |
|
8e7383cbe56e
Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents:
45484
diff
changeset
|
123 self.assertRaises(ValueError, mod.insort_right, [1, 2, 3], 5, -1, 3), |
|
8e7383cbe56e
Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents:
45484
diff
changeset
|
124 |
|
27269
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
125 def test_random(self, n=25): |
|
27267
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
126 from random import randrange |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
127 for i in xrange(n): |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
128 data = [randrange(0, n, 2) for j in xrange(i)] |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
129 data.sort() |
|
27269
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
130 elem = randrange(-1, n+1) |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
131 ip = self.module.bisect_left(data, elem) |
|
27267
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
132 if ip < len(data): |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
133 self.failUnless(elem <= data[ip]) |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
134 if ip > 0: |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
135 self.failUnless(data[ip-1] < elem) |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
136 ip = self.module.bisect_right(data, elem) |
|
27267
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
137 if ip < len(data): |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
138 self.failUnless(elem < data[ip]) |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
139 if ip > 0: |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
140 self.failUnless(data[ip-1] <= elem) |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
141 |
|
27268
be3d1b7e62dc
Test optional slice arguments.
Raymond Hettinger <python@rcn.com>
parents:
27267
diff
changeset
|
142 def test_optionalSlicing(self): |
|
27269
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
143 for func, data, elem, expected in self.precomputedCases: |
|
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
144 for lo in xrange(4): |
|
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
145 lo = min(len(data), lo) |
|
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
146 for hi in xrange(3,8): |
|
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
147 hi = min(len(data), hi) |
|
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
148 ip = func(data, elem, lo, hi) |
|
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
149 self.failUnless(lo <= ip <= hi) |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
150 if func is self.module.bisect_left and ip < hi: |
|
27269
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
151 self.failUnless(elem <= data[ip]) |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
152 if func is self.module.bisect_left and ip > lo: |
|
27269
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
153 self.failUnless(data[ip-1] < elem) |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
154 if func is self.module.bisect_right and ip < hi: |
|
27269
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
155 self.failUnless(elem < data[ip]) |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
156 if func is self.module.bisect_right and ip > lo: |
|
27269
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
157 self.failUnless(data[ip-1] <= elem) |
|
dbe4f57e8bb2
Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents:
27268
diff
changeset
|
158 self.assertEqual(ip, max(lo, min(hi, expected))) |
|
27268
be3d1b7e62dc
Test optional slice arguments.
Raymond Hettinger <python@rcn.com>
parents:
27267
diff
changeset
|
159 |
|
be3d1b7e62dc
Test optional slice arguments.
Raymond Hettinger <python@rcn.com>
parents:
27267
diff
changeset
|
160 def test_backcompatibility(self): |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
161 self.assertEqual(self.module.bisect, self.module.bisect_right) |
|
27268
be3d1b7e62dc
Test optional slice arguments.
Raymond Hettinger <python@rcn.com>
parents:
27267
diff
changeset
|
162 |
|
35699
3572249c1e77
SF #1313496: bisect C replacement doesn't accept named args
Raymond Hettinger <python@rcn.com>
parents:
33602
diff
changeset
|
163 def test_keyword_args(self): |
|
3572249c1e77
SF #1313496: bisect C replacement doesn't accept named args
Raymond Hettinger <python@rcn.com>
parents:
33602
diff
changeset
|
164 data = [10, 20, 30, 40, 50] |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
165 self.assertEqual(self.module.bisect_left(a=data, x=25, lo=1, hi=3), 2) |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
166 self.assertEqual(self.module.bisect_right(a=data, x=25, lo=1, hi=3), 2) |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
167 self.assertEqual(self.module.bisect(a=data, x=25, lo=1, hi=3), 2) |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
168 self.module.insort_left(a=data, x=25, lo=1, hi=3) |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
169 self.module.insort_right(a=data, x=25, lo=1, hi=3) |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
170 self.module.insort(a=data, x=25, lo=1, hi=3) |
|
35699
3572249c1e77
SF #1313496: bisect C replacement doesn't accept named args
Raymond Hettinger <python@rcn.com>
parents:
33602
diff
changeset
|
171 self.assertEqual(data, [10, 20, 25, 25, 25, 30, 40, 50]) |
|
3572249c1e77
SF #1313496: bisect C replacement doesn't accept named args
Raymond Hettinger <python@rcn.com>
parents:
33602
diff
changeset
|
172 |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
173 class TestBisectPython(TestBisect): |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
174 module = py_bisect |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
175 |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
176 class TestBisectC(TestBisect): |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
177 module = c_bisect |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
178 |
|
27266
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
179 #============================================================================== |
|
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
180 |
|
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
181 class TestInsort(unittest.TestCase): |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
182 module = None |
|
15673
67b3ac439f64
Fred, THIS NEEDS DOCS! The function docstrings tell the tale.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
183 |
|
31353
ed20259a1ea5
SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
184 def test_vsBuiltinSort(self, n=500): |
|
27266
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
185 from random import choice |
|
31353
ed20259a1ea5
SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
186 for insorted in (list(), UserList()): |
|
ed20259a1ea5
SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
187 for i in xrange(n): |
|
ed20259a1ea5
SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
188 digit = choice("0123456789") |
|
ed20259a1ea5
SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
189 if digit in "02468": |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
190 f = self.module.insort_left |
|
31353
ed20259a1ea5
SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
191 else: |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
192 f = self.module.insort_right |
|
31353
ed20259a1ea5
SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
193 f(insorted, digit) |
|
ed20259a1ea5
SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents:
28917
diff
changeset
|
194 self.assertEqual(sorted(insorted), insorted) |
|
27266
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
195 |
|
27268
be3d1b7e62dc
Test optional slice arguments.
Raymond Hettinger <python@rcn.com>
parents:
27267
diff
changeset
|
196 def test_backcompatibility(self): |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
197 self.assertEqual(self.module.insort, self.module.insort_right) |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
198 |
|
49677
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47919
diff
changeset
|
199 def test_listDerived(self): |
|
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47919
diff
changeset
|
200 class List(list): |
|
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47919
diff
changeset
|
201 data = [] |
|
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47919
diff
changeset
|
202 def insert(self, index, item): |
|
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47919
diff
changeset
|
203 self.data.insert(index, item) |
|
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47919
diff
changeset
|
204 |
|
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47919
diff
changeset
|
205 lst = List() |
|
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47919
diff
changeset
|
206 self.module.insort_left(lst, 10) |
|
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47919
diff
changeset
|
207 self.module.insort_right(lst, 5) |
|
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47919
diff
changeset
|
208 self.assertEqual([5, 10], lst.data) |
|
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47919
diff
changeset
|
209 |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
210 class TestInsortPython(TestInsort): |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
211 module = py_bisect |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
212 |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
213 class TestInsortC(TestInsort): |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
214 module = c_bisect |
|
27268
be3d1b7e62dc
Test optional slice arguments.
Raymond Hettinger <python@rcn.com>
parents:
27267
diff
changeset
|
215 |
|
27266
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
216 #============================================================================== |
|
15673
67b3ac439f64
Fred, THIS NEEDS DOCS! The function docstrings tell the tale.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
217 |
|
33601
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
218 |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
219 class LenOnly: |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
220 "Dummy sequence class defining __len__ but not __getitem__." |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
221 def __len__(self): |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
222 return 10 |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
223 |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
224 class GetOnly: |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
225 "Dummy sequence class defining __getitem__ but not __len__." |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
226 def __getitem__(self, ndx): |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
227 return 10 |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
228 |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
229 class CmpErr: |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
230 "Dummy element that always raises an error during comparison" |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
231 def __cmp__(self, other): |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
232 raise ZeroDivisionError |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
233 |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
234 class TestErrorHandling(unittest.TestCase): |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
235 module = None |
|
33601
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
236 |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
237 def test_non_sequence(self): |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
238 for f in (self.module.bisect_left, self.module.bisect_right, |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
239 self.module.insort_left, self.module.insort_right): |
|
33601
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
240 self.assertRaises(TypeError, f, 10, 10) |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
241 |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
242 def test_len_only(self): |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
243 for f in (self.module.bisect_left, self.module.bisect_right, |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
244 self.module.insort_left, self.module.insort_right): |
|
33601
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
245 self.assertRaises(AttributeError, f, LenOnly(), 10) |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
246 |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
247 def test_get_only(self): |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
248 for f in (self.module.bisect_left, self.module.bisect_right, |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
249 self.module.insort_left, self.module.insort_right): |
|
33601
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
250 self.assertRaises(AttributeError, f, GetOnly(), 10) |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
251 |
|
33602
7d6679ee39f9
Rename test for comparision errors.
Raymond Hettinger <python@rcn.com>
parents:
33601
diff
changeset
|
252 def test_cmp_err(self): |
|
33601
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
253 seq = [CmpErr(), CmpErr(), CmpErr()] |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
254 for f in (self.module.bisect_left, self.module.bisect_right, |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
255 self.module.insort_left, self.module.insort_right): |
|
33601
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
256 self.assertRaises(ZeroDivisionError, f, seq, 10) |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
257 |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
258 def test_arg_parsing(self): |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
259 for f in (self.module.bisect_left, self.module.bisect_right, |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
260 self.module.insort_left, self.module.insort_right): |
|
33601
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
261 self.assertRaises(TypeError, f, 10) |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
262 |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
263 class TestErrorHandlingPython(TestErrorHandling): |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
264 module = py_bisect |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
265 |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
266 class TestErrorHandlingC(TestErrorHandling): |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
267 module = c_bisect |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
268 |
|
33601
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
269 #============================================================================== |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
270 |
|
27267
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
271 libreftest = """ |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
272 Example from the Library Reference: Doc/library/bisect.rst |
|
27267
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
273 |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
274 The bisect() function is generally useful for categorizing numeric data. |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
275 This example uses bisect() to look up a letter grade for an exam total |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
276 (say) based on a set of ordered numeric breakpoints: 85 and up is an `A', |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
277 75..84 is a `B', etc. |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
278 |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
279 >>> grades = "FEDCBA" |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
280 >>> breakpoints = [30, 44, 66, 75, 85] |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
281 >>> from bisect import bisect |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
282 >>> def grade(total): |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
283 ... return grades[bisect(breakpoints, total)] |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
284 ... |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
285 >>> grade(66) |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
286 'C' |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
287 >>> map(grade, [33, 99, 77, 44, 12, 88]) |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
288 ['E', 'A', 'B', 'D', 'F', 'A'] |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
289 |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
290 """ |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
291 |
|
27266
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
292 #------------------------------------------------------------------------------ |
|
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
293 |
|
27267
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
294 __test__ = {'libreftest' : libreftest} |
|
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
295 |
|
27266
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
296 def test_main(verbose=None): |
|
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
297 from test import test_bisect |
|
33601
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
298 |
|
45484
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
299 test_classes = [TestBisectPython, TestBisectC, |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
300 TestInsortPython, TestInsortC, |
|
8531f88b578e
In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents:
35699
diff
changeset
|
301 TestErrorHandlingPython, TestErrorHandlingC] |
|
33601
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
302 |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
303 test_support.run_unittest(*test_classes) |
|
27267
b744508d5b12
Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents:
27266
diff
changeset
|
304 test_support.run_doctest(test_bisect, verbose) |
|
27266
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
305 |
|
33601
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
306 # verify reference counting |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
307 if verbose and hasattr(sys, "gettotalrefcount"): |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
308 import gc |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
309 counts = [None] * 5 |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
310 for i in xrange(len(counts)): |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
311 test_support.run_unittest(*test_classes) |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
312 gc.collect() |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
313 counts[i] = sys.gettotalrefcount() |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
314 print counts |
|
7511585f2e6a
Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents:
31436
diff
changeset
|
315 |
|
27266
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
316 if __name__ == "__main__": |
|
a9ddadf789ea
Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents:
24442
diff
changeset
|
317 test_main(verbose=True) |
