Exemplo n.º 1
0
 def test_twoelem(self):
     obj = self.Object
     lst = [obj(1), obj(3)]
     self.assertEqual(binary_search(lst, 0), -1)
     self.assertEqual(binary_search(lst, 1), 0)
     self.assertEqual(binary_search(lst, 2), 0)
     self.assertEqual(binary_search(lst, 3), 1)
     self.assertEqual(binary_search(lst, 4), 1)
Exemplo n.º 2
0
 def test_listsize(self):
     obj = self.Object
     for l in range(3, 32):
         lst = [obj(_ + 1) for _ in range(l)]
         lst = lst[:1] + lst[2:]
         self.assertEqual(binary_search(lst, 0), -1)
         self.assertEqual(binary_search(lst, 1), 0)
         self.assertEqual(binary_search(lst, 2), 0)
         self.assertEqual(binary_search(lst, 3), 1)
         self.assertEqual(binary_search(lst, l - 1), l - 3)
         self.assertEqual(binary_search(lst, l), l - 2)
         self.assertEqual(binary_search(lst, l + 1), l - 2)
         self.assertEqual(binary_search(lst, l + 2), l - 2)
Exemplo n.º 3
0
 def test_bs(self):
     obj = self.Object
     lst = [obj(_) for _ in (2, 3, 5, 6)]
     self.assertEqual(binary_search(lst, 1), -1)
     self.assertEqual(binary_search(lst, 2), 0)
     self.assertEqual(binary_search(lst, 3), 1)
     self.assertEqual(binary_search(lst, 4), 1)
     self.assertEqual(binary_search(lst, 5), 2)
     self.assertEqual(binary_search(lst, 6), 3)
     self.assertEqual(binary_search(lst, 7), 3)
Exemplo n.º 4
0
 def test_oneelem(self):
     obj = self.Object
     lst = [obj(1)]
     self.assertEqual(binary_search(lst, 0), -1)
     self.assertEqual(binary_search(lst, 1), 0)
     self.assertEqual(binary_search(lst, 2), 0)
Exemplo n.º 5
0
 def test_emptylist(self):
     obj = self.Object
     lst = []
     self.assertEqual(binary_search(lst, 1), -1)