-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_stack.py
43 lines (34 loc) · 1.06 KB
/
test_stack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import unittest
from stack import Stack
class TestStack(unittest.TestCase):
def test_constructor(self):
stack = Stack()
self.assertEqual(stack.size(), 0)
self.assertIsNone(stack.head.Value)
self.assertIsNone(stack.tail)
def test_push(self):
stack = Stack()
stack.push(14)
self.assertEqual(stack.head.next.Value, 14)
stack.push(16)
self.assertEqual(stack.size(), 2)
def test_pop(self):
stack = Stack()
self.assertIsNone(stack.pop())
stack.push(14)
self.assertEqual(stack.pop(), 14)
self.assertEqual(stack.size(), 0)
def test_size(self):
stack = Stack()
self.assertEqual(stack.size(), 0)
for i in range(1000):
stack.push(i)
self.assertEqual(stack.size(), 1000)
def test_peek(self):
stack = Stack()
self.assertIsNone(stack.peek())
stack.push(19)
self.assertEqual(stack.peek(), 19)
self.assertEqual(stack.size(), 1)
if __name__ == '__main__':
unittest.main()