def test_binary_search(self): sol = Solution() self.assertEqual(sol.search([1, 2, 3, 4, 5], 3), 2) self.assertEqual(sol.search([1, 2, 3, 4, 5], 6), -1) self.assertEqual(sol.search([1, 2, 3, 4, 5], 0), -1) self.assertEqual(sol.search([1, 2, 3, 4, 5], 5), 4) self.assertEqual(sol.search([1, 2, 3, 4, 5], 1), 0) self.assertEqual(sol.search([1, 2, 3, 4, 5], 2), 1) self.assertEqual(sol.search([1, 2, 3, 4, 5], 4), 3)
def test_sample_2(self): self.assertEquals(Solution().search([-1, 0, 3, 5, 9, 12], 2), -1)
def test_self_2(self): self.assertEquals(Solution().search([-1, 0, 3, 5, 9, 12], 15), -1)
def test_2_5(self): self.assertEqual(Solution().binarySearchIterate([0,1,21,33,45,45,61,71,72,73],70),-1)
def test_2_4(self): self.assertEqual(Solution().binarySearchIterate([0,1,21,33,45,45,61,71,72,73,355],354),-1)
def test_binary_search(self): solution = Solution() self.assertEqual(solution.search(nums=[-1, 0, 3, 5, 9, 12], target=9), 4) self.assertEqual(solution.search(nums=[-1, 0, 3, 5, 9, 12], target=2), -1)
def test_example_2(self): assert Solution().search(nums=[-1, 0, 3, 5, 9, 12], target=2) == -1