interactive-coding-challenges/stacks_queues/stack_min/test_stack_min.py

44 lines
1.1 KiB
Python
Raw Normal View History

2015-07-03 11:06:09 +08:00
from nose.tools import assert_equal
class TestStackMin(object):
2015-07-12 03:39:59 +08:00
2015-07-03 11:06:09 +08:00
def test_stack_min(self):
print('Test: Push on empty stack, non-empty stack')
stack = MyStack()
stack.push(5)
assert_equal(stack.peek(), 5)
assert_equal(stack.min(), 5)
stack.push(1)
assert_equal(stack.peek(), 1)
assert_equal(stack.min(), 1)
stack.push(3)
assert_equal(stack.peek(), 3)
assert_equal(stack.min(), 1)
stack.push(0)
assert_equal(stack.peek(), 0)
assert_equal(stack.min(), 0)
print('Test: Pop on non-empty stack')
assert_equal(stack.pop(), 0)
assert_equal(stack.min(), 1)
assert_equal(stack.pop(), 3)
assert_equal(stack.min(), 1)
assert_equal(stack.pop(), 1)
assert_equal(stack.min(), 5)
assert_equal(stack.pop(), 5)
assert_equal(stack.min(), sys.maxsize)
2015-07-03 11:06:09 +08:00
print('Test: Pop empty stack')
assert_equal(stack.pop(), None)
2015-07-12 03:39:59 +08:00
2015-07-03 11:06:09 +08:00
print('Success: test_stack_min')
2015-07-12 03:39:59 +08:00
2015-07-03 11:06:09 +08:00
def main():
test = TestStackMin()
test.test_stack_min()
2015-07-12 03:39:59 +08:00
2015-07-03 11:06:09 +08:00
if __name__ == '__main__':
main()