Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
 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)
Пример #4
0
 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)
Пример #5
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)
Пример #6
0
 def test13(self):
     A = [1]
     sol = Solution()
     rtn = sol.bs_get_idx_last_less_or_equal(A, 1)
     self.assertEqual(rtn, 0)
Пример #7
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)
Пример #8
0
 def test11(self):
     A = []
     sol = Solution()
     rtn = sol.bs_get_idx_first_greater_or_equal(A, 5)
     self.assertEqual(rtn, 0)
Пример #9
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)
Пример #10
0
 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)
Пример #11
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)