Пример #1
0
    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())
Пример #2
0
    def test_size_withDifferentTimeUpdates_shouldReturnCorrectSizeOfStackAfterOperations(
            self):
        s = StackFR()
        self.assertEqual(0, s.size())

        for i in range(1, 40):
            s.push(i, i)
            self.assertEqual(i, s.size())

        for i in range(1, 40):
            s.pop(i + 0.5)
            self.assertEqual(0, s.size(i + 0.5))
Пример #3
0
    def test_size_withUpdatesAlwaysInPresentTimeAndCheckingCurrentTime_shouldBehaveAsEphemeralStack(
            self):
        s = StackFR()
        self.assertEqual(0, s.size())

        for i in range(1, 40):
            s.push(i, i)
            self.assertEqual(i, s.size())
            self.assertEqual(i, s.size(i + 0.5))

        for i in range(1, 40):
            s.pop(40 + i)
            self.assertEqual(39 - i, s.size())
Пример #4
0
 def test_constructor_shouldCreateEmptyStack(self):
     s = StackFR()
     self.assertEqual(0, s.size())
     self.assertIsNone(s.top())