def test_delete_withExistingOperationInGivenTime_shouldDeleteOperationAndPropagateItsEffects( self): q = QueueFR() # q = [enqueue(1), dequeue(), ..., enqueue(t), dequeue()] # q will be an empty queue at the end of the loop for t in range(1, 20): q.enqueue(t, t) q.dequeue(t + 0.5) self.assertEqual(0, q.size()) self.assertIsNone(q.back()) self.assertIsNone(q.front()) # Deleting all dequeue operations # q = [1, 2, ..., 19] for t in range(1, 20): q.delete(t + 0.5) self.assertEqual(t, q.size()) self.assertEqual(19, q.back()) self.assertEqual(20 - t, q.front()) # Deleting all enqueue operations # q = [] for t in range(1, 20): q.delete(t) self.assertEqual(19 - t, q.size()) if t == 19: self.assertIsNone(q.back()) self.assertIsNone(q.front()) else: self.assertEqual(19, q.back()) self.assertEqual(t + 1, q.front())
def test_front_withUpdatesInCurrentTime_shouldReturnCurrentFrontOfQueue( self): q = QueueFR() for i in range(1, 20): q.enqueue(i, i) self.assertEqual(1, q.front()) for i in range(1, 20): q.dequeue(20 + i) if i == 19: self.assertIsNone(q.front()) else: self.assertEqual(i + 1, q.front())
def test_enqueue_withDifferentTimes_shouldEnqueueValueAtGivenTime(self): q = QueueFR() # Should behave as ephemeral queue for t in range(20): q.enqueue(t, t) self.assertEqual(0, q.front()) self.assertEqual(t, q.back()) for t in range(1, 20): q.enqueue(t + 0.5, t + 0.5) self.assertEqual(0, q.front(t + 0.5)) self.assertEqual(t + 0.5, q.back(t + 0.5))
def test_dequeue_withUpdatesInCurrentTime_shouldRemoveAndReturnFrontOfCurrentQueue( self): # Should behave as ephemeral queue q = QueueFR() for t in range(20): q.enqueue(t, t) for t in range(20): self.assertEqual(t, q.dequeue(20 + t)) if t == 19: self.assertIsNone(q.front()) else: self.assertEqual(t + 1, q.front())
def test_front_withUpdatesInDifferentTimes_shouldReturnCorrectFrontOfQueueAtGivenTime( self): q = QueueFR() for t in range(20): q.enqueue(t, t) for t in range(20): self.assertEqual(t, q.dequeue(t + 0.5)) self.assertIsNone(q.front(t + 0.5))
def test_dequeue_withDifferentTimeUpdates_shouldRemoveAndReturnFrontOfQueueAtGivenTime( self): q = QueueFR() for t in range(1, 20): q.enqueue(t, t) for t in range(1, 20): self.assertEqual(t, q.dequeue(t + 0.5)) self.assertIsNone(q.front(t + 0.5))
def test_constructor_shouldCreateEmptyQueue(self): q = QueueFR() self.assertEqual(0, q.size()) self.assertIsNone(q.back()) self.assertIsNone(q.front())
def test_front_withEmptyQueueAtGivenTimes_shouldReturnNone(self): q = QueueFR() self.assertIsNone(q.front()) for i in range(-20, 20): self.assertIsNone(q.front(i))