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."))
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)))
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))
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))
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"))
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)))
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))
def test_wrong_initial_capacity(self): with self.assertRaises(ValueError) as context: Semaphore(-1) self.assertTrue( check_error_message(context, WRONG_CAPACITY_ERROR_MESSAGE))
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))