Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
test.test_bisect.TestBisect Class Reference
Inheritance diagram for test.test_bisect.TestBisect:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def setUp
def test_precomputed
def test_negative_lo
def test_random
def test_optionalSlicing
def test_backcompatibility
def test_keyword_args

Public Attributes

 precomputedCases

Static Public Attributes

 module = None

Detailed Description

Definition at line 26 of file test_bisect.py.


Member Function Documentation

Definition at line 29 of file test_bisect.py.

00029 
00030     def setUp(self):
00031         self.precomputedCases = [
00032             (self.module.bisect_right, [], 1, 0),
00033             (self.module.bisect_right, [1], 0, 0),
00034             (self.module.bisect_right, [1], 1, 1),
00035             (self.module.bisect_right, [1], 2, 1),
00036             (self.module.bisect_right, [1, 1], 0, 0),
00037             (self.module.bisect_right, [1, 1], 1, 2),
00038             (self.module.bisect_right, [1, 1], 2, 2),
00039             (self.module.bisect_right, [1, 1, 1], 0, 0),
00040             (self.module.bisect_right, [1, 1, 1], 1, 3),
00041             (self.module.bisect_right, [1, 1, 1], 2, 3),
00042             (self.module.bisect_right, [1, 1, 1, 1], 0, 0),
00043             (self.module.bisect_right, [1, 1, 1, 1], 1, 4),
00044             (self.module.bisect_right, [1, 1, 1, 1], 2, 4),
00045             (self.module.bisect_right, [1, 2], 0, 0),
00046             (self.module.bisect_right, [1, 2], 1, 1),
00047             (self.module.bisect_right, [1, 2], 1.5, 1),
00048             (self.module.bisect_right, [1, 2], 2, 2),
00049             (self.module.bisect_right, [1, 2], 3, 2),
00050             (self.module.bisect_right, [1, 1, 2, 2], 0, 0),
00051             (self.module.bisect_right, [1, 1, 2, 2], 1, 2),
00052             (self.module.bisect_right, [1, 1, 2, 2], 1.5, 2),
00053             (self.module.bisect_right, [1, 1, 2, 2], 2, 4),
00054             (self.module.bisect_right, [1, 1, 2, 2], 3, 4),
00055             (self.module.bisect_right, [1, 2, 3], 0, 0),
00056             (self.module.bisect_right, [1, 2, 3], 1, 1),
00057             (self.module.bisect_right, [1, 2, 3], 1.5, 1),
00058             (self.module.bisect_right, [1, 2, 3], 2, 2),
00059             (self.module.bisect_right, [1, 2, 3], 2.5, 2),
00060             (self.module.bisect_right, [1, 2, 3], 3, 3),
00061             (self.module.bisect_right, [1, 2, 3], 4, 3),
00062             (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 0, 0),
00063             (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1, 1),
00064             (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1.5, 1),
00065             (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2, 3),
00066             (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2.5, 3),
00067             (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3, 6),
00068             (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3.5, 6),
00069             (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 4, 10),
00070             (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 5, 10),
00071 
00072             (self.module.bisect_left, [], 1, 0),
00073             (self.module.bisect_left, [1], 0, 0),
00074             (self.module.bisect_left, [1], 1, 0),
00075             (self.module.bisect_left, [1], 2, 1),
00076             (self.module.bisect_left, [1, 1], 0, 0),
00077             (self.module.bisect_left, [1, 1], 1, 0),
00078             (self.module.bisect_left, [1, 1], 2, 2),
00079             (self.module.bisect_left, [1, 1, 1], 0, 0),
00080             (self.module.bisect_left, [1, 1, 1], 1, 0),
00081             (self.module.bisect_left, [1, 1, 1], 2, 3),
00082             (self.module.bisect_left, [1, 1, 1, 1], 0, 0),
00083             (self.module.bisect_left, [1, 1, 1, 1], 1, 0),
00084             (self.module.bisect_left, [1, 1, 1, 1], 2, 4),
00085             (self.module.bisect_left, [1, 2], 0, 0),
00086             (self.module.bisect_left, [1, 2], 1, 0),
00087             (self.module.bisect_left, [1, 2], 1.5, 1),
00088             (self.module.bisect_left, [1, 2], 2, 1),
00089             (self.module.bisect_left, [1, 2], 3, 2),
00090             (self.module.bisect_left, [1, 1, 2, 2], 0, 0),
00091             (self.module.bisect_left, [1, 1, 2, 2], 1, 0),
00092             (self.module.bisect_left, [1, 1, 2, 2], 1.5, 2),
00093             (self.module.bisect_left, [1, 1, 2, 2], 2, 2),
00094             (self.module.bisect_left, [1, 1, 2, 2], 3, 4),
00095             (self.module.bisect_left, [1, 2, 3], 0, 0),
00096             (self.module.bisect_left, [1, 2, 3], 1, 0),
00097             (self.module.bisect_left, [1, 2, 3], 1.5, 1),
00098             (self.module.bisect_left, [1, 2, 3], 2, 1),
00099             (self.module.bisect_left, [1, 2, 3], 2.5, 2),
00100             (self.module.bisect_left, [1, 2, 3], 3, 2),
00101             (self.module.bisect_left, [1, 2, 3], 4, 3),
00102             (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 0, 0),
00103             (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1, 0),
00104             (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1.5, 1),
00105             (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2, 1),
00106             (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2.5, 3),
00107             (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3, 3),
00108             (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3.5, 6),
00109             (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 4, 6),
00110             (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 5, 10)
00111         ]

Here is the caller graph for this function:

Definition at line 160 of file test_bisect.py.

00160 
00161     def test_backcompatibility(self):
00162         self.assertEqual(self.module.bisect, self.module.bisect_right)

Here is the call graph for this function:

Definition at line 163 of file test_bisect.py.

00163 
00164     def test_keyword_args(self):
00165         data = [10, 20, 30, 40, 50]
00166         self.assertEqual(self.module.bisect_left(a=data, x=25, lo=1, hi=3), 2)
00167         self.assertEqual(self.module.bisect_right(a=data, x=25, lo=1, hi=3), 2)
00168         self.assertEqual(self.module.bisect(a=data, x=25, lo=1, hi=3), 2)
00169         self.module.insort_left(a=data, x=25, lo=1, hi=3)
00170         self.module.insort_right(a=data, x=25, lo=1, hi=3)
00171         self.module.insort(a=data, x=25, lo=1, hi=3)
00172         self.assertEqual(data, [10, 20, 25, 25, 25, 30, 40, 50])

Here is the call graph for this function:

Definition at line 117 of file test_bisect.py.

00117 
00118     def test_negative_lo(self):
00119         # Issue 3301
00120         mod = self.module
00121         self.assertRaises(ValueError, mod.bisect_left, [1, 2, 3], 5, -1, 3),
00122         self.assertRaises(ValueError, mod.bisect_right, [1, 2, 3], 5, -1, 3),
00123         self.assertRaises(ValueError, mod.insort_left, [1, 2, 3], 5, -1, 3),
00124         self.assertRaises(ValueError, mod.insort_right, [1, 2, 3], 5, -1, 3),

Here is the call graph for this function:

Definition at line 142 of file test_bisect.py.

00142 
00143     def test_optionalSlicing(self):
00144         for func, data, elem, expected in self.precomputedCases:
00145             for lo in range(4):
00146                 lo = min(len(data), lo)
00147                 for hi in range(3,8):
00148                     hi = min(len(data), hi)
00149                     ip = func(data, elem, lo, hi)
00150                     self.assertTrue(lo <= ip <= hi)
00151                     if func is self.module.bisect_left and ip < hi:
00152                         self.assertTrue(elem <= data[ip])
00153                     if func is self.module.bisect_left and ip > lo:
00154                         self.assertTrue(data[ip-1] < elem)
00155                     if func is self.module.bisect_right and ip < hi:
00156                         self.assertTrue(elem < data[ip])
00157                     if func is self.module.bisect_right and ip > lo:
00158                         self.assertTrue(data[ip-1] <= elem)
00159                     self.assertEqual(ip, max(lo, min(hi, expected)))

Here is the call graph for this function:

Definition at line 112 of file test_bisect.py.

00112 
00113     def test_precomputed(self):
00114         for func, data, elem, expected in self.precomputedCases:
00115             self.assertEqual(func(data, elem), expected)
00116             self.assertEqual(func(UserList(data), elem), expected)

Here is the call graph for this function:

def test.test_bisect.TestBisect.test_random (   self,
  n = 25 
)

Definition at line 125 of file test_bisect.py.

00125 
00126     def test_random(self, n=25):
00127         from random import randrange
00128         for i in range(n):
00129             data = [randrange(0, n, 2) for j in range(i)]
00130             data.sort()
00131             elem = randrange(-1, n+1)
00132             ip = self.module.bisect_left(data, elem)
00133             if ip < len(data):
00134                 self.assertTrue(elem <= data[ip])
00135             if ip > 0:
00136                 self.assertTrue(data[ip-1] < elem)
00137             ip = self.module.bisect_right(data, elem)
00138             if ip < len(data):
00139                 self.assertTrue(elem < data[ip])
00140             if ip > 0:
00141                 self.assertTrue(data[ip-1] <= elem)

Here is the call graph for this function:


Member Data Documentation

Reimplemented in test.test_bisect.TestBisectC, and test.test_bisect.TestBisectPython.

Definition at line 27 of file test_bisect.py.

Definition at line 30 of file test_bisect.py.


The documentation for this class was generated from the following file: