MCPcopy
hub / github.com/keon/algorithms / test_array_stack

Method test_array_stack

tests/test_stack.py:77–107  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

75
76class TestStack(unittest.TestCase):
77 def test_array_stack(self):
78 stack = ArrayStack()
79 stack.push(1)
80 stack.push(2)
81 stack.push(3)
82
83 # test __iter__()
84 it = iter(stack)
85 self.assertEqual(3, next(it))
86 self.assertEqual(2, next(it))
87 self.assertEqual(1, next(it))
88 self.assertRaises(StopIteration, next, it)
89
90 # test __len__()
91 self.assertEqual(3, len(stack))
92
93 # test __str__()
94 self.assertEqual(str(stack), "Top-> 3 2 1")
95
96 # test is_empty()
97 self.assertFalse(stack.is_empty())
98
99 # test peek()
100 self.assertEqual(3, stack.peek())
101
102 # test pop()
103 self.assertEqual(3, stack.pop())
104 self.assertEqual(2, stack.pop())
105 self.assertEqual(1, stack.pop())
106
107 self.assertTrue(stack.is_empty())
108
109 def test_linked_list_stack(self):
110 stack = LinkedListStack()

Callers

nothing calls this directly

Calls 5

pushMethod · 0.95
peekMethod · 0.95
popMethod · 0.95
ArrayStackClass · 0.90
is_emptyMethod · 0.45

Tested by

no test coverage detected