예제 #1
0
def init_stack():
    new_stack = Stack()
    my_list = [1, 2, 3, 4]
    for el in my_list:
        new_stack.push(el)

    return new_stack
def test_enqueue_two():
    queue = PseudoQueue()
    queue.enqueue(Stack())
    queue.front.push('Front')
    queue.enqueue(Stack())
    queue.rear.push('Rear')
    assert queue.front.peek() == 'Front' and queue.rear.peek() == 'Rear'
def my_stack():
    new_stack = Stack()
    values = ["a", "b", "c", 10]
    for el in values:
        new_stack.push(el)

    return new_stack
예제 #4
0
def my_stack():
    new_stack = Stack()
    values = ['a', 'b', 'c', 10]
    for el in values:
        new_stack.push(el)

    return new_stack
def test_dequeue_two():
    queue = PseudoQueue()
    queue.enqueue(Stack())
    queue.front.push('First')
    queue.enqueue(Stack())
    queue.rear.push('Second')
    assert queue.dequeue().peek() == 'First' and queue.dequeue().peek(
    ) == 'Second'
def test_peek():
    s = Stack()
    s.push("apple")
    s.push("banana")
    actual = s.peek()
    expected = "banana"
    assert actual == expected
예제 #7
0
def test_PseudoQueue_init_stack():
	stack_one = Stack()
	stack_one.push(15)
	stack_one.push(10)
	stack_one.push(5)
	stack_one.push(0)
	queue = PseudoQueue(stack_one)
	actual = str(queue)
	expected = '0 ->5 ->10 ->15'
	assert actual == expected
def test_enqueue_empty_stack():
    pseudo_q = PseudoQueue(Stack())
    pseudo_q.enqueue("cat")
    assert pseudo_q.stack1.peek() == "cat"
def test_stack():
    stack = Stack()
    with pytest.raises(InvalidOperationError) as error:
        stack.peek()
    assert str(error.value) == "Method not allowed on empty collection."
def test_dequeue_one():
    queue = PseudoQueue()
    queue.enqueue(Stack())
    queue.front.push('First')
    assert queue.dequeue().peek() == 'First'
def test_enqueue_empty():
    queue = PseudoQueue()
    queue.enqueue(Stack())
    with pytest.raises(InvalidOperationError) as error:
        queue.front.peek()
    assert str(error.value) == "Method not allowed on empty collection."
예제 #12
0
def test_stack_instance():
    assert Stack()
def test_pop_single():
    s = Stack()
    s.push("apple")
    actual = s.pop()
    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
예제 #15
0
def new_stack():
    print('in new list')
    test_stack = Stack()
    for i in range(1, 20):
        test_stack.push(i)
    return test_stack
def test_dequeue_empty():
    pseudo_q = PseudoQueue(Stack())
    with pytest.raises(Exception):
        result = pseudo_q.dequeue()
def test_pop_empty():
    s = Stack()
    with pytest.raises(InvalidOperationError) as e:
        s.pop()

    assert str(e.value) == "Method not allowed on empty collection"