コード例 #1
0
def test_push_pop_empty():
    stack = Stack()
    assert stack.empty()

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

    assert stack.empty()
コード例 #2
0
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)