Esempio n. 1
0
 def __init__(self):
     """Initialise push and pop stacks
     """
     # Create stack elements need to be on when adding to queue
     self.add_stack = Stack()
     # Create stack elements need to be on when removing from queue
     self.remove_stack = Stack()
     # Use boolean to track last operation
     self.just_added = True
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
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
Esempio n. 5
0
    def __init__(self):
        """Initialise stack as is done for Stack, but also introduce stack
        to track min values
        """
        # Initialise Stack
        super().__init__()

        # Use this stack to track min vals
        self.min_vals = Stack()
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
import pytest
from data_structures.stacks_and_queues.stack import Stack
from data_structures.stacks_and_queues.pseudo_queue import PseudoQueue, InvalidOperationError

test_stack = Stack()
test_stack.push(11)
test_stack.push(12)
test_stack.push(20)

@pytest.mark.skip
def test_enqueue():
    q = PseudoQueue()
    q.enqueue("apple")
    actual = q.top.value
    expected = "apple"
    assert actual == expected

@pytest.mark.skip
def test_dequeue():
    q = PseudoQueue()
    q.enqueue("apple")
    q.enqueue("banana")
    actual = q.dequeue()
    expected = "apple"
    assert actual == expected

@pytest.mark.skip
def test_peek():
    q = PseudoQueue()
    q.enqueue("apple")
    q.enqueue("banana")
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_push_onto_empty():
    s = Stack()
    s.push("apple")
    actual = s.top.value
    expected = "apple"
    assert actual == expected
def test_pop_single():
    s = Stack()
    s.push("apple")
    actual = s.pop()
    expected = "apple"
    assert actual == expected