interactive-coding-challenges/stacks_queues/stack/test_stack.py

43 lines
1.1 KiB
Python
Raw Normal View History

2015-07-03 11:06:52 +08:00
from nose.tools import assert_equal
class TestStack(object):
2015-07-12 03:39:59 +08:00
2015-07-03 11:06:52 +08:00
# TODO: It would be better if we had unit tests for each
# method in addition to the following end-to-end test
def test_end_to_end(self):
print('Test: Empty stack')
stack = Stack()
assert_equal(stack.peek(), None)
assert_equal(stack.pop(), None)
print('Test: One element')
top = Node(5)
stack = Stack(top)
assert_equal(stack.pop(), 5)
assert_equal(stack.peek(), None)
print('Test: More than one element')
stack = Stack()
stack.push(1)
stack.push(2)
stack.push(3)
assert_equal(stack.pop(), 3)
assert_equal(stack.peek(), 2)
assert_equal(stack.pop(), 2)
assert_equal(stack.peek(), 1)
assert_equal(stack.is_empty(), False)
assert_equal(stack.pop(), 1)
assert_equal(stack.peek(), None)
assert_equal(stack.is_empty(), True)
2015-07-12 03:39:59 +08:00
2015-07-03 11:06:52 +08:00
print('Success: test_end_to_end')
2015-07-12 03:39:59 +08:00
2015-07-03 11:06:52 +08:00
def main():
test = TestStack()
test.test_end_to_end()
2015-07-12 03:39:59 +08:00
2015-07-03 11:06:52 +08:00
if __name__ == '__main__':
main()