def setUp(self): self.stack = MinStack()
class TestStackMin(unittest.TestCase): def setUp(self): self.stack = MinStack() def test_push_and_peek(self): for i in range(10): self.stack.push(i) self.assertEquals(self.stack.peek(), i) def test_push_and_pop(self): for i in range(10): self.stack.push(i) for i in range(9, -1, -1): self.assertEquals(self.stack.pop(), i) def test_min(self): TEST_DATA = [ [10, 5, 3, 8, 2, 2, 6, 7, 1], [10, 5, 3, 3, 2, 2, 2, 2, 1], [1, 2, 2, 2, 2, 3, 3, 5, 10]] for i in range(len(TEST_DATA[0])): self.stack.push(TEST_DATA[0][i]) self.assertEquals(self.stack.min(), TEST_DATA[1][i]) for i in range(len(TEST_DATA[0])): self.assertEquals(self.stack.min(), TEST_DATA[2][i]) self.stack.pop() def test_corner_cases(self): with self.assertRaises(KeyError): self.stack.pop() self.assertEquals(self.stack.peek(), None) self.assertEquals(self.stack.min(), None)