def test7(self): A = [1, 1, 1, 1, 1, 1] sol = Solution() rtn = sol.bs_get_idx_first_greater_or_equal(A, 4) self.assertEqual(rtn, len(A)) rtn = sol.bs_get_idx_last_less_or_equal(A, 2) self.assertEqual(rtn, len(A) - 1)
def test6(self): A = [1, 1, 1, 1, 5, 6, 7, 8] sol = Solution() rtn = sol.bs_get_idx_first_greater_or_equal(A, 3) self.assertEqual(rtn, 4) rtn = sol.bs_get_idx_last_less_or_equal(A, 1) self.assertEqual(rtn, 3) rtn = sol.bs_get_idx_last_less_or_equal(A, 2) self.assertEqual(rtn, 3)
def test_find_equal_1(self): A = [1, 3, 5, 7, 9] sol = Solution() rtn = sol.bs_find_equal(A, 9) self.assertEqual(rtn, 4) rtn = sol.bs_find_equal(A, 4) self.assertEqual(rtn, None) rtn = sol.bs_find_equal(A, 0) self.assertEqual(rtn, None) rtn = sol.bs_find_equal(A, 10) self.assertEqual(rtn, None) rtn = sol.bs_find_equal(A, 1) self.assertEqual(rtn, 0) rtn = sol.bs_find_equal(A, 3) self.assertEqual(rtn, 1)
def test_find_left_most_greater_1(self): A = [1, 3, 5, 7, 9] sol = Solution() rtn = sol.bs_find_left_most_greater(A, 9) self.assertEqual(rtn, None) rtn = sol.bs_find_left_most_greater(A, 8) self.assertEqual(rtn, 4) rtn = sol.bs_find_left_most_greater(A, 7) self.assertEqual(rtn, 4) rtn = sol.bs_find_left_most_greater(A, 1) self.assertEqual(rtn, 1) rtn = sol.bs_find_left_most_greater(A, 0) self.assertEqual(rtn, 0)
def test_find_right_most_smaller_or_equal_1(self): A = [1, 3, 5, 7, 9] sol = Solution() rtn = sol.bs_find_right_most_smaller_or_equal(A, 9) self.assertEqual(rtn, 4) rtn = sol.bs_find_right_most_smaller_or_equal(A, 8) self.assertEqual(rtn, 3) rtn = sol.bs_find_right_most_smaller_or_equal(A, 7) self.assertEqual(rtn, 3) rtn = sol.bs_find_right_most_smaller_or_equal(A, 10) self.assertEqual(rtn, 4) rtn = sol.bs_find_right_most_smaller_or_equal(A, 0) self.assertEqual(rtn, None)
def test13(self): A = [1] sol = Solution() rtn = sol.bs_get_idx_last_less_or_equal(A, 1) self.assertEqual(rtn, 0)
def test12(self): A = [4, 4, 4, 4, 5, 5, 5, 7, 8, 9] sol = Solution() rtn = sol.bs_get_idx_last_less_or_equal(A, 6) self.assertEqual(rtn, 6)
def test11(self): A = [] sol = Solution() rtn = sol.bs_get_idx_first_greater_or_equal(A, 5) self.assertEqual(rtn, 0)
def test10(self): A = [4, 4, 4, 4, 5, 5, 5, 6, 7, 8, 9] sol = Solution() rtn = sol.bs_get_idx_first_greater_or_equal(A, 5) self.assertEqual(rtn, 4)
def test8(self): A = [5, 6, 7, 8, 9] sol = Solution() rtn = sol.bs_get_idx_first_greater_or_equal(A, 4) self.assertEqual(rtn, 0)
def test_find_left_most_greater_or_equal_1(self): A = [1, 3, 5, 7, 9] sol = Solution() rtn = sol.bs_find_left_most_greater_or_equal(A, 10) self.assertEqual(rtn, None) rtn = sol.bs_find_left_most_greater_or_equal(A, 9) self.assertEqual(rtn, 4) rtn = sol.bs_find_left_most_greater_or_equal(A, 8) self.assertEqual(rtn, 4) rtn = sol.bs_find_left_most_greater_or_equal(A, 7) self.assertEqual(rtn, 3) rtn = sol.bs_find_left_most_greater_or_equal(A, 1) self.assertEqual(rtn, 0) rtn = sol.bs_find_left_most_greater_or_equal(A, 0) self.assertEqual(rtn, 0) A = [1, 3] rtn = sol.bs_find_left_most_greater_or_equal(A, 0) self.assertEqual(rtn, 0) rtn = sol.bs_find_left_most_greater_or_equal(A, 1) self.assertEqual(rtn, 0) rtn = sol.bs_find_left_most_greater_or_equal(A, 3) self.assertEqual(rtn, 1) rtn = sol.bs_find_left_most_greater_or_equal(A, 5) self.assertEqual(rtn, None) A = [1] rtn = sol.bs_find_left_most_greater_or_equal(A, 1) self.assertEqual(rtn, 0) rtn = sol.bs_find_left_most_greater_or_equal(A, 2) self.assertEqual(rtn, None)