-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_stack.py
More file actions
48 lines (37 loc) · 1.37 KB
/
Copy pathtest_stack.py
File metadata and controls
48 lines (37 loc) · 1.37 KB
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
44
45
46
47
48
import unittest
import stack
class StackTest(unittest.TestCase):
def test_create_stack(self):
test_stack = stack.Stack()
self.assertEqual(test_stack.size(), 0)
def test_push_stack(self):
test_stack = stack.Stack()
test_stack.push(5)
self.assertEqual(test_stack.size(), 1)
test_stack.push('two')
self.assertEqual(test_stack.size(), 2)
test_stack.push(True)
self.assertEqual(test_stack.size(), 3)
self.assertIsInstance(test_stack.pop(), bool)
self.assertIsInstance(test_stack.pop(), str)
self.assertIsInstance(test_stack.pop(), int)
self.assertEqual(test_stack.size(), 0)
def test_peek_stack(self):
test_stack = stack.Stack()
test_stack.push(5)
self.assertEqual(test_stack.peek(), 5)
test_stack.push("Three")
self.assertEqual(test_stack.peek(), "Three")
test_stack.push(False)
self.assertEqual(test_stack.peek(), False)
def test_pop_stack(self):
test_stack = stack.Stack()
test_stack.push(5)
test_stack.push("hello")
test_stack.push(True)
self.assertEqual(test_stack.pop(), True)
self.assertEqual(test_stack.pop(), "hello")
self.assertEqual(test_stack.pop(), 5)
self.assertEqual(test_stack.is_empty(), True)
if __name__ == "__main__":
unittest.main()