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

45 lines
1.2 KiB
Python
Raw Normal View History

import unittest
2015-07-03 11:06:09 +08:00
class TestStackMin(unittest.TestCase):
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 = StackMin()
2015-07-03 11:06:09 +08:00
stack.push(5)
self.assertEqual(stack.peek(), 5)
self.assertEqual(stack.minimum(), 5)
2015-07-03 11:06:09 +08:00
stack.push(1)
self.assertEqual(stack.peek(), 1)
self.assertEqual(stack.minimum(), 1)
2015-07-03 11:06:09 +08:00
stack.push(3)
self.assertEqual(stack.peek(), 3)
self.assertEqual(stack.minimum(), 1)
2015-07-03 11:06:09 +08:00
stack.push(0)
self.assertEqual(stack.peek(), 0)
self.assertEqual(stack.minimum(), 0)
2015-07-03 11:06:09 +08:00
print('Test: Pop on non-empty stack')
self.assertEqual(stack.pop(), 0)
self.assertEqual(stack.minimum(), 1)
self.assertEqual(stack.pop(), 3)
self.assertEqual(stack.minimum(), 1)
self.assertEqual(stack.pop(), 1)
self.assertEqual(stack.minimum(), 5)
self.assertEqual(stack.pop(), 5)
self.assertEqual(stack.minimum(), sys.maxsize)
2015-07-03 11:06:09 +08:00
print('Test: Pop empty stack')
self.assertEqual(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__':
2018-09-08 08:50:20 +08:00
main()