summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-01-16 14:00:15 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-01-16 14:00:15 (GMT)
commit6aa1c3f4cc1e59e7aa5806c49916e2846aaceeb0 (patch)
tree8ed5e269e9d83c6e16beedadc95a4744d8e06d50
parenta9f18dc0f095cf7e8e00e57a135a88b0f6104f73 (diff)
downloadcpython-6aa1c3f4cc1e59e7aa5806c49916e2846aaceeb0.zip
cpython-6aa1c3f4cc1e59e7aa5806c49916e2846aaceeb0.tar.gz
cpython-6aa1c3f4cc1e59e7aa5806c49916e2846aaceeb0.tar.bz2
Let test_random cover the endpoints.
Strengthen slicing tests. Improved variable names.
-rw-r--r--Lib/test/test_bisect.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/Lib/test/test_bisect.py b/Lib/test/test_bisect.py
index d641b53..076e818 100644
--- a/Lib/test/test_bisect.py
+++ b/Lib/test/test_bisect.py
@@ -87,15 +87,15 @@ class TestBisect(unittest.TestCase):
]
def test_precomputed(self):
- for func, list, elt, expected in self.precomputedCases:
- self.assertEqual(func(list, elt), expected)
+ for func, data, elem, expected in self.precomputedCases:
+ self.assertEqual(func(data, elem), expected)
- def test_random(self, n=20):
+ def test_random(self, n=25):
from random import randrange
for i in xrange(n):
data = [randrange(0, n, 2) for j in xrange(i)]
data.sort()
- elem = randrange(n)
+ elem = randrange(-1, n+1)
ip = bisect_left(data, elem)
if ip < len(data):
self.failUnless(elem <= data[ip])
@@ -108,11 +108,22 @@ class TestBisect(unittest.TestCase):
self.failUnless(data[ip-1] <= elem)
def test_optionalSlicing(self):
- for func, list, elt, expected in self.precomputedCases:
- lo = min(len(list), 1)
- self.failUnless(func(list, elt, lo=lo) >= lo)
- hi = min(len(list), 2)
- self.failUnless(func(list, elt, hi=hi) <= hi)
+ for func, data, elem, expected in self.precomputedCases:
+ for lo in xrange(4):
+ lo = min(len(data), lo)
+ for hi in xrange(3,8):
+ hi = min(len(data), hi)
+ ip = func(data, elem, lo, hi)
+ self.failUnless(lo <= ip <= hi)
+ if func is bisect_left and ip < hi:
+ self.failUnless(elem <= data[ip])
+ if func is bisect_left and ip > lo:
+ self.failUnless(data[ip-1] < elem)
+ if func is bisect_right and ip < hi:
+ self.failUnless(elem < data[ip])
+ if func is bisect_right and ip > lo:
+ self.failUnless(data[ip-1] <= elem)
+ self.assertEqual(ip, max(lo, min(hi, expected)))
def test_backcompatibility(self):
self.assertEqual(bisect, bisect_right)