def test_peek(stack_3_vals):

    assert stack_3_vals.peek() == 'd'
    assert stack_3_vals.top.value == 'd'

    # for Empty stack, we expect an exception

    empty = Stack()
    assert empty.peek() == 'this is an empty Stack'
def test_pop(stack_3_vals):

    assert stack_3_vals.pop() == 'd'
    assert stack_3_vals.top.value == -7
    assert stack_3_vals.pop() == -7
    assert stack_3_vals.pop() == 3
    # now we reach the empty stack
    assert stack_3_vals.pop() == 'this is an empty Stack'

    # for Empty stack, we expect an exception

    empty = Stack()
    assert empty.pop() == 'this is an empty Stack'
def test_push_onto_full():
    s = Stack()
    s.push("apple")
    s.push("banana")
    s.push("cucumber")
    actual = s.top.value
    expected = "cucumber"
    assert actual == expected
def test_peek():
    s = Stack()
    s.push("apple")
    s.push("banana")
    actual = s.peek()
    expected = "banana"
    assert actual == expected
def test_check_not_empty():
    s = Stack()
    s.push("apple")
    s.push("banana")
    actual = s.is_empty()
    expected = False
    assert actual == expected
class PseudoQueue():
    def __init__(self):
        self.stack1 = Stack()
        self.stack2 = Stack()

    def enqueue(self, value):
        """
        Args:
            value ([int]): [inserts the value to stack1 using FIFO]
        """
        self.stack1.push(value)

    def dequeue(self):
        """[Return the "first in" value from stack1.]

        Returns:
            [int/value]: [the first in value from stack1]
        """
        while self.stack1.peek():
            if self.stack1.top.next == None:
                return self.stack1.top.value
            else:
                temp = self.stack1.pop()
                self.stack2.push(temp)
                continue
def stack_3_vals():
    stack = Stack()
    stack.push(3)
    stack.push(-7)
    stack.push('d')
    return stack
 def __init__(self):
     self.stack1 = Stack()
     self.stack2 = Stack()
def test_pop_empty():
    s = Stack()
    with pytest.raises(InvalidOperationError) as e:
        s.pop()

    assert str(e.value) == "Method not allowed on empty collection"
def test_pop_until_empty():
    s = Stack()
    s.push("apple")
    s.push("banana")
    s.push("cucumber")
    s.pop()
    s.pop()
    s.pop()
    actual = s.is_empty()
    expected = True
    assert actual == expected
def test_push_onto_empty():
    s = Stack()
    s.push("apple")
    actual = s.top.value
    expected = "apple"
    assert actual == expected
def test_pop_some():
    s = Stack()

    s.push("apple")
    s.push("banana")
    s.push("cucumber")

    s.pop()

    actual = s.pop()
    expected = "banana"

    assert actual == expected
def test_pop_single():
    s = Stack()
    s.push("apple")
    actual = s.pop()
    expected = "apple"
    assert actual == expected