Exemplo n.º 1
0
    def test_get_size(self):
        stack = LinkedListStack()
        expected = 0
        actual = stack.get_size()
        self.assertEqual(expected, actual)

        stack.push(42)
        stack.push(42)
        stack.push(42)
        stack.pop()

        expected = 2
        actual = stack.get_size()
        self.assertEqual(expected, actual)
Exemplo n.º 2
0
    def test_pop(self):
        stack = LinkedListStack()

        self.assertIsNone(stack.pop())
        expected = 42
        stack.push(expected + 2)
        stack.push(expected + 1)
        stack.push(expected)

        actual = stack.pop()
        self.assertEqual(expected, actual)

        actual = stack.pop()
        self.assertEqual(expected + 1, actual)

        actual = stack.pop()
        self.assertEqual(expected + 2, actual)
Exemplo n.º 3
0
 def test_push(self):
     stack = LinkedListStack()
     expected = 42
     stack.push(expected)
     stack.push(expected + 1)
     actual = stack.pop()
     self.assertEqual(expected + 1, actual)
Exemplo n.º 4
0
    def test_iterator(self):
        stack = LinkedListStack()
        expected = 42
        stack.push(expected)
        stack.push(expected + 1)

        iterator = stack.__iter__()
        actual1 = iterator.__next__()
        actual2 = iterator.__next__()
        self.assertEqual(expected + 1, actual1)
        self.assertEqual(expected, actual2)
Exemplo n.º 5
0
    def test_is_empty(self):
        stack = LinkedListStack()
        actual = stack.is_empty()
        self.assertTrue(actual)

        stack.push(42)
        actual = stack.is_empty()
        self.assertFalse(actual)
Exemplo n.º 6
0
 def test_str(self):
     stack = LinkedListStack()
     stack.push(42)
     stack.push(43)
     stack.push(44)
     expected = "44\n43\n42\n"
     actual = str(stack)
     self.assertEqual(expected, actual)
Exemplo n.º 7
0
    def test_clear(self):
        stack = LinkedListStack()
        self.assertTrue(stack.is_empty())

        expected = 42
        stack.push(expected + 2)
        stack.push(expected + 1)
        stack.push(expected)

        self.assertFalse(stack.is_empty())
        self.assertEqual(3, stack.get_size())

        stack.clear()

        self.assertTrue(stack.is_empty())
        self.assertEqual(0, stack.get_size())
        self.assertIsNone(stack.pop())
Exemplo n.º 8
0
    def test_peek(self):
        stack = LinkedListStack()
        self.assertIsNone(stack.peek())

        expected = 42
        stack.push(expected + 2)
        stack.push(expected + 1)
        stack.push(expected)

        self.assertEqual(3, stack.get_size())

        actual = stack.peek()
        self.assertEqual(expected, actual)

        self.assertEqual(3, stack.get_size())

        actual = stack.pop()
        self.assertEqual(expected, actual)