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_pop_some(): s = Stack() s.push("apple") s.push("banana") s.push("cucumber") s.pop() actual = s.pop() expected = "banana" 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 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_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_single(): s = Stack() s.push("apple") actual = s.pop() expected = "apple" assert actual == expected