def test_lifo():
    stack = Stack()

    stack.push(5)
    stack.push(6)
    assert stack.pop() == 6
    assert stack.pop() == 5
Example #2
0
def stack_reverse(l):
    s = Stack(len(l))
    for e in l:
        s.push(e)
    r = []
    while not s.is_empty():
        r.append(s.pop())
    return r
def test_push_pop_empty():
    stack = Stack()
    assert stack.empty()

    stack.push(5)
    assert stack.pop() == 5

    assert stack.empty()
def test_capacity():
    # Create a stack that can hold a single element only.
    stack = Stack(1)
    assert stack.empty()

    stack.push(5)

    # Attempting to push an additional item should fail.
    with pytest.raises(TypeError) as e_info:
        stack.push(6)
Example #5
0
 def setUp(self):
     self.stack = Stack()
Example #6
0
 def setUp(self):
     self.stack = Stack()
     self.stack.push(1)
     self.stack.push(2)
     self.stack.push(3)
def test_pop():
    stack = Stack()
    with pytest.raises(TypeError) as e_info:
        stack.pop()