-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlab_stack_test.py
More file actions
57 lines (36 loc) · 1.47 KB
/
lab_stack_test.py
File metadata and controls
57 lines (36 loc) · 1.47 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
49
50
51
52
53
54
55
56
57
from lab_stack import *
import unittest
class StackTest(unittest.TestCase):
def setUp(self):
self.testvalues = 'abcde'
self.s = Stack( len(self.testvalues) )
def tearDown(self):
pass
def test_size(self):
""" test that stack reports the correct number of things on the stack """
for index, val in enumerate(self.testvalues):
self.assertEqual( self.s.num_items(), index )
self.s.push( val )
for i in range(len(self.testvalues), 0, -1):
self.assertEqual( self.s.num_items(), i )
self.s.pop()
self.assertEqual( self.s.num_items(), 0 )
def test_empty(self):
""" test that stack raises Empty exception when popping an empty stack """
self.assertRaises( Stack.Empty, self.s.pop )
self.s.push( self.testvalues[0] )
self.s.pop()
self.assertRaises( Stack.Empty, self.s.pop )
def test_full(self):
""" test that the stack raises Full exception when push on a full stack """
for i in self.testvalues:
self.s.push(i)
self.assertRaises( Stack.Full, self.s.push, 'a' )
def test_top(self):
""" test that the stack reports the correct values on the top of the stack """
self.assertRaises( Stack.Empty, self.s.top )
for i in self.testvalues:
self.s.push(i)
self.assertEqual( self.s.top(), i )
if __name__ == '__main__':
unittest.main()