def stack(request):
    """Creating a Stack object"""
    stack = Stack()
    stack.push(10)
    stack.push(30)
    stack.push(40)
    stack.push(20)
    return stack
Exemple #2
0
def test_stack_linked_list():

    # initialize nodes and stack
    node_1 = Node(2)
    node_2 = Node(24)
    node_3 = Node(-31)
    node_4 = Node(0)
    stack = StackLL()

    # test push()
    stack.push(node_1)
    stack.push(node_2)
    stack.push(node_3)
    stack.push(node_4)
    assert stack.to_string() == '0 -> -31 -> 24 -> 2 -> '

    # test pop()
    stack.pop()
    stack.pop()
    assert stack.to_string() == '24 -> 2 -> '
    stack.pop()
    stack.pop()
    assert stack.to_string() == ''
    stack.pop()

    # test peek()
    node_5 = Node(7)
    node_6 = Node(-1)
    stack.push(node_5)
    stack.push(node_6)
    assert stack.peek() == node_6
    stack.pop()
    stack.pop()
    stack.pop()
    assert stack.peek() == None
    assert stack.to_string() == ''

    # test is_empty()
    assert stack.is_empty()
    node_7 = Node(10)
    stack.push(node_7)
    assert not stack.is_empty()

    # test nuke()
    assert stack.to_string() == '10 -> '
    stack.nuke()
    assert stack.is_empty()
    assert stack.to_string() == ''
def test_get_max_empty_stack():
    stack = Stack()
    assert not stack.get_max()
def test_stack_len_empty_stack():
    stack = Stack()
    assert 0 == stack.stack_len(stack.peek)
def test_get_peek_empty_stack():
    stack = Stack()
    assert not stack.get_peek()
def test_is_empty():
    stack = Stack()
    assert stack.is_empty()
def test_pop_last_item():
    stack = Stack()
    stack.push(1)
    assert 1 == stack.pop()
def test_pop_from_empty_stack():
    stack = Stack()
    assert not stack.pop()