def test_empty():
    s = MyStack()
    assert 1 == s.isEmpty()
    s.push(1)
    assert 0 == s.isEmpty()
    s.pop()
    assert 1 == s.isEmpty()
def test_peek():
    s = MyStack()
    s.push(1)
    s.push(2)
    assert 2 == s.peek()
    s.push(3)
    assert 3 == s.peek()
    s.pop()
    assert 2 == s.peek()
def test_size():
    s = MyStack()
    s.push(1)
    s.push(2)
    s.push(3)
    assert 3 == s.size()
    s.pop()
    assert 2 == s.size()
    s.push(4)
    assert 3 == s.size()
def test_sort():
    s = MyStack()
    s.push(2)
    s.push(3)
    s.push(1)
    s.push(10)
    s.push(5)
    s.sort()
    assert 10 == s.pop()
    assert 5 == s.pop()
    assert 3 == s.pop()
    assert 2 == s.pop()
    assert 1 == s.pop()
Пример #5
0
class StackMin:
    def __init__(self):
        self.sMin = MyStack()

    def push(self,data):
        if data < self.min():
            self.sMin.push(data)
        self.push(data)

    def pop(self):
        val = self.pop()
        if val == self.sMin.min():
            self.sMin.pop()
        return val

    def min(self):
        return self.sMin.peek()
def test_pop():
    s = MyStack()
    s.push(1)
    s.push(2)
    assert 2 == s.pop()
    assert 1 == s.pop()