예제 #1
0
    def test_get_no_key_in_treap(self):
        node = TreapNode(10, "100")
        with self.assertRaises(KeyError) as context:
            node.get(20)

        self.assertTrue(
            check_error_message(context, "Key '20' isn't in the treap."))
예제 #2
0
    def test_delete_no_key_in_treap(self):
        treap = Treap()
        treap[202] = "a"
        treap[303] = "b"

        with self.assertRaises(KeyError) as context:
            del treap[0]
        self.assertTrue(check_error_message(context, get_message_about_key_absence(0)))
예제 #3
0
    def test_released_too_many_times_one_thread(self):
        semaphore = Semaphore()

        with self.assertRaises(ValueError) as context:
            semaphore.release()

        self.assertTrue(
            check_error_message(context,
                                RELEASED_TOO_MANY_TIMES_ERROR_MESSAGE))
예제 #4
0
    def test_release_after_initialization(self):
        semaphore = Semaphore(3)

        with self.assertRaises(ValueError) as context:
            semaphore.release()

        self.assertTrue(
            check_error_message(context,
                                RELEASED_TOO_MANY_TIMES_ERROR_MESSAGE))
예제 #5
0
    def test_update_no_key_in_treap(self):
        node = TreapNode(10, "100")
        with self.assertRaises(KeyError) as context:
            node.update(20, "100")

        self.assertTrue(
            check_error_message(
                context,
                "Unable to update because there is no key '20' in the treap"))
예제 #6
0
    def test_get_no_key_in_treap(self):
        treap = Treap()
        treap[-100] = 100
        treap[100] = -100

        with self.assertRaises(KeyError) as context:
            treap[101]

        self.assertTrue(check_error_message(context, get_message_about_key_absence(101)))
예제 #7
0
    def test_released_too_many_times_two_threads(self):
        semaphore = Semaphore()

        def use_semaphore():
            with semaphore:
                pass

        thread = Thread(target=use_semaphore)
        thread.start()
        thread.join()

        with self.assertRaises(ValueError) as context:
            semaphore.release()

        self.assertTrue(
            check_error_message(context,
                                RELEASED_TOO_MANY_TIMES_ERROR_MESSAGE))
예제 #8
0
    def test_wrong_initial_capacity(self):
        with self.assertRaises(ValueError) as context:
            Semaphore(-1)

        self.assertTrue(
            check_error_message(context, WRONG_CAPACITY_ERROR_MESSAGE))
예제 #9
0
    def test_get(self):
        treap = Treap()
        with self.assertRaises(KeyError) as context:
            treap[100]

        self.assertTrue(check_error_message(context, TREAP_IS_EMPTY_ERROR_MESSAGE))