def test_delete_withExistingOperationInGivenTime_shouldDeleteOperationAndPropagateItsEffects( self): s = StackFR() # s = [push(1), pop(), ..., push(t), pop()] # s will be an empty stack at the end of the loop for t in range(1, 20): s.push(t, t) s.pop(t + 0.5) self.assertEqual(0, s.size()) self.assertIsNone(s.top()) # Deleting all pop operations # s = [19, 18, ..., 1] for t in range(1, 20): s.delete(t + 0.5) self.assertEqual(t, s.size()) self.assertEqual(t, s.top()) # Deleting all push operations # s = [] for t in range(1, 20): s.delete(t) self.assertEqual(19 - t, s.size()) if t == 19: self.assertIsNone(s.top()) else: self.assertEqual(19, s.top())
def test_delete_withNoExistingOperationInGivenTime_shouldRaiseValueError( self): s = StackFR() for i in range(-20, 20): with self.assertRaises(ValueError): s.delete(i) for i in range(20): s.push(i, i) for i in range(20): with self.assertRaises(ValueError): s.delete(i + 0.5)