2020-07-09 07:57:55 +08:00
|
|
|
import unittest
|
2015-07-03 11:06:09 +08:00
|
|
|
|
|
|
|
|
2020-07-09 07:57:55 +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')
|
2016-06-20 18:54:08 +08:00
|
|
|
stack = StackMin()
|
2015-07-03 11:06:09 +08:00
|
|
|
stack.push(5)
|
2020-07-09 07:57:55 +08:00
|
|
|
self.assertEqual(stack.peek(), 5)
|
|
|
|
self.assertEqual(stack.minimum(), 5)
|
2015-07-03 11:06:09 +08:00
|
|
|
stack.push(1)
|
2020-07-09 07:57:55 +08:00
|
|
|
self.assertEqual(stack.peek(), 1)
|
|
|
|
self.assertEqual(stack.minimum(), 1)
|
2015-07-03 11:06:09 +08:00
|
|
|
stack.push(3)
|
2020-07-09 07:57:55 +08:00
|
|
|
self.assertEqual(stack.peek(), 3)
|
|
|
|
self.assertEqual(stack.minimum(), 1)
|
2015-07-03 11:06:09 +08:00
|
|
|
stack.push(0)
|
2020-07-09 07:57:55 +08:00
|
|
|
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')
|
2020-07-09 07:57:55 +08:00
|
|
|
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')
|
2020-07-09 07:57:55 +08:00
|
|
|
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()
|