示例#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_push_withDifferentTimes_shouldPushValueAtGivenTime(self):
        s = StackFR()

        # Should behave as ephemeral stack
        for t in range(1, 20):
            s.push(t, t)
            self.assertEqual(t, s.top())

        for t in range(1, 20):
            s.push(t + 0.5, t + 0.5)
            self.assertEqual(t + 0.5, s.top(t + 0.5))
示例#3
0
 def test_top_withUpdatesInCurrentTime_shouldReturnCurrentTopOfStack(self):
     s = StackFR()
     for i in range(1, 20):
         s.push(i, i)
         self.assertEqual(i, s.top())
     for i in range(1, 20):
         s.pop(20 + i)
         if i == 19:
             self.assertIsNone(s.top())
         else:
             self.assertEqual(19 - i, s.top())
示例#4
0
    def test_pop_withUpdatesInCurrentTime_shouldRemoveAndReturnTopOfCurrentStack(
            self):
        # Should behave as ephemeral stack
        s = StackFR()

        for t in range(1, 20):
            s.push(t, t)

        for t in range(1, 20):
            if t == 19:
                self.assertIsNone(s.pop(20 + t))
                self.assertIsNone(s.top())
            else:
                self.assertEqual(20 - t, s.top())
                s.pop(20 + t)
                self.assertEqual(20 - t - 1, s.top())
示例#5
0
 def test_now(self):
     s = StackFR()
     s.push(50, 1)
     s.push(51, 5)
     s.push(52, 8)
     s.pop(3)
     s.pop(10)
     self.assertEqual(51, s.top(10))
示例#6
0
    def test_top_withUpdatesInDifferentTimes_shouldReturnCorrectTopOfStackAtGivenTime(
            self):
        s = StackFR()

        for t in range(1, 20):
            s.push(t, t)

        for t in range(1, 20):
            s.pop(t + 0.5)
            self.assertIsNone(s.top(t + 0.5))
示例#7
0
    def test_pop_withDifferentTimeUpdates_shouldRemoveAndReturnTopOfStackAtGivenTime(
            self):
        s = StackFR()

        for t in range(1, 20):
            s.push(t, t)

        for t in range(1, 20):
            s.pop(t + 0.5)
            self.assertIsNone(s.top(t + 0.5))
示例#8
0
 def test_constructor_shouldCreateEmptyStack(self):
     s = StackFR()
     self.assertEqual(0, s.size())
     self.assertIsNone(s.top())
示例#9
0
    def test_top_withEmptyStackAtGivenTimes_shouldReturnNone(self):
        s = StackFR()
        self.assertIsNone(s.top())

        for i in range(-20, 20):
            self.assertIsNone(s.top(i))