Skip to content

Commit 7803311

Browse files
committed
Renamed EmptyStack exception to make more sense and added non functioning unit tests for now.
1 parent a86ac1c commit 7803311

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

algorithms/data_structures/stack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Stacks are cool
33
"""
44

5-
class EmptyStackException(Exception):
5+
class EmptyStackError(Exception):
66
pass
77

88
class Element(object):
@@ -20,7 +20,7 @@ def push(self, element):
2020

2121
def pop(self):
2222
if self.empty():
23-
raise EmptyStackException
23+
raise EmptyStackError
2424
result = self.head.value
2525
self.head = self.head.next
2626
return result
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import unittest
2+
from ..data_structures import Stack, EmptyStackError
3+
4+
class TestStack(unittest.TestCase):
5+
"""
6+
Tests the methods of the Stack data structure.
7+
"""
8+
9+
def setUp(self):
10+
self.input = range(5)
11+
self.stack = Stack()
12+
self.reverse = [5, 4, 3, 2, 1]
13+
14+
def test_stack(self):
15+
for i in self.input:
16+
self.stack.push(i)
17+
18+
result = []
19+
20+
while not self.stack.empty():
21+
result.append(self.stack.pop())
22+
23+
self.assertEqual(self.reverse, result)
24+
self.assertRaises(EmptyStackError, self.stack.empty())

0 commit comments

Comments
 (0)