def test_min_works():
    m = MinStack()
    minimum = 1000
    for _ in range(1000):
        x = randint(-500, 500)
        minimum = min(minimum, x)
        m.push(x)

    assert m.minimum == minimum
def test_stack_works():
    m = MinStack()
    test_stack = []
    for _ in range(1000):
        x = randint(-500, 500)
        test_stack.append(x)
        m.push(x)

    for _ in range(1000):
        assert test_stack.pop() == m.pop()
Beispiel #3
0
 def setUp(self):
     self.stack = MinStack()
Beispiel #4
0
class TestMinStack(unittest.TestCase):
    def setUp(self):
        self.stack = MinStack()

    def test_min_set(self):
        self.assertEqual(self.stack.min(), None)
        self.stack.push(3)
        self.assertEqual(self.stack.min(), 3)
        self.stack.push(24)
        self.assertEqual(self.stack.min(), 3)
        self.stack.push(5)
        self.stack.push(1)
        self.assertEqual(self.stack.min(), 1)
        self.stack.push(0)
        self.assertEqual(self.stack.min(), 0)
        self.stack.push(10)
        self.assertEqual(self.stack.min(), 0)
        self.stack.pop()
        self.assertEqual(self.stack.min(), 0)
        self.stack.pop()
        self.assertEqual(self.stack.min(), 1)
        self.stack.pop()
        self.stack.pop()
        self.assertEqual(self.stack.min(), 3)
Beispiel #5
0
 def setUp(self):
     self.stack = MinStack()
Beispiel #6
0
class TestMinStack(unittest.TestCase):

    def setUp(self):
        self.stack = MinStack()

    def test_min_set(self):
        self.assertEqual(self.stack.min(), None)
        self.stack.push(3)
        self.assertEqual(self.stack.min(), 3)
        self.stack.push(24)
        self.assertEqual(self.stack.min(), 3)
        self.stack.push(5)
        self.stack.push(1)
        self.assertEqual(self.stack.min(), 1)
        self.stack.push(0)
        self.assertEqual(self.stack.min(), 0)
        self.stack.push(10)
        self.assertEqual(self.stack.min(), 0)
        self.stack.pop()
        self.assertEqual(self.stack.min(), 0)
        self.stack.pop()
        self.assertEqual(self.stack.min(), 1)
        self.stack.pop()
        self.stack.pop()
        self.assertEqual(self.stack.min(), 3)