def test_existing(self): self.assertEqual(binary_search(5, self.arr), 5, msg="Invalid index returned!") self.assertEqual(binary_search(54, self.arr), 54, msg="Invalid index returned!")
def test_borders(self): self.assertEqual( binary_search(0, self.arr), 0, msg="First element is not found - maybe 'mid - 1' is missing?") self.assertEqual( binary_search(101, self.arr), 100, msg="Last element is not found - maybe 'mid + 1' is missing?")
def test_missing(self): self.assertIsNone( binary_search(-1, self.arr), msg= "Answer should be None because element is not presented in the array" ) self.assertIsNone( binary_search(100, self.arr), msg= "Answer should be None because element is not presented in the array" )
def test_existing(self): self.assertEqual(5, binary_search(5, self.arr), msg="Invalid index returned!") self.assertEqual(54, binary_search(54, self.arr), msg="Invalid index returned!") self.assertEqual( 1, binary_search(2, [1, 2, 2, 2]), msg="You should return first occurrence from the array.") self.assertEqual( 0, binary_search(2, [2, 2, 2, 2]), msg="You should return first occurrence from the array.")