def test_push_many():
    """
    Can successfully push multiple nodes onto a stack
    """

    fruits = Stack()

    fruits.push('apple')
    fruits.push('pear')

    expected = 'pear'

    assert expected == fruits.peek_stack()
def test_push_one():
    """
    Can successfully push onto a stack
    Can successfully peek the next item on the stack.
    """

    fruits = Stack()

    fruits.push('apple')

    expected = 'apple'

    assert expected == fruits.peek_stack()
def test_pop():
    """
    Can successfully pop off the stack
    Can successfully empty a stack after multiple pops.
    """

    fruits = Stack()

    fruits.push('apple')
    fruits.push('pear')
    fruits.pop()
    fruits.pop()

    assert 'No value.' == fruits.peek_stack()
Пример #4
0
 def depth_first(self,node):
     stack = Stack()
     stack.push(node)
     seen =[]
     while stack.peek_stack() is not None:
         current = stack.pop()
         if current.visited == False:
             seen.append(current.value)
             current.visited = True
             for i in current.list:
                 stack.push(i[0])
             if current.visited is False:
                 stack.pop()    
     return seen