-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
42 lines (29 loc) · 795 Bytes
/
stack.py
File metadata and controls
42 lines (29 loc) · 795 Bytes
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
import unittest
class Stack(object):
def __init__(self):
self.stack = []
def clear(self):
self.stack.clear()
def is_empty(self):
return len(self.stack) == 0
def push(self, value):
self.stack.append(value)
def pop(self):
return self.stack.pop()
class TestStack(unittest.TestCase):
def test(self):
data_set = [1, 2, 3, 4, 5]
stack = Stack()
stack.clear()
for data in data_set:
stack.push(data)
result = []
while not stack.is_empty():
value = stack.pop()
if value is not None:
result.append(value)
self.assertEqual(
result, [5, 4, 3, 2, 1]
)
if __name__ == '__main__':
unittest.TestCase()