Ejemplo n.º 1
0
def test_peek_node_value_at_top_of_stack():
    new_stack = Stack()
    new_stack.push(5)
    new_stack.push(6)
    new_stack.peek()
    actual = new_stack.peek()
    expected = 6
    assert actual == expected
def initial_stack():
    initial_stack = Stack()
    initial_stack.push("a")
    initial_stack.push("b")
    initial_stack.push("c")
    initial_stack.push("d")
    return initial_stack
Ejemplo n.º 3
0
def test_node_top_value_afetr_pop():
    new_stack = Stack()
    new_stack.push(5)
    new_stack.push(6)
    new_stack.pop()
    actual = new_stack.top.value
    expected = 5
    assert actual == expected
Ejemplo n.º 4
0
 def __init__(self):
     self.stack1 = Stack()
     self.stack2 = Stack()
Ejemplo n.º 5
0
class PseudoQueue:
    def __init__(self):
        self.stack1 = Stack()
        self.stack2 = Stack()

    def enqueue(self, value):
        self.stack1.push(value)

    def dequeue(self):

        if self.stack1.isEmpty():
            raise Exception("PseudoQue is empty")

        while not self.stack1.isEmpty():
            popped = self.stack1.pop()
            self.stack2.push(popped)

        dequed = self.stack2.pop()

        while not self.stack2.isEmpty():
            popped = self.stack2.pop()
            self.stack1.push(popped)

        return dequed

    def isEmpty(self):
        return self.stack1.isEmpty()
Ejemplo n.º 6
0
def test_check_empty_stack():
    new_stack = Stack()
    actual = new_stack.isEmpty()
    expected = True
    assert actual == expected
Ejemplo n.º 7
0
def test_push_value():
    new_stack = Stack()
    new_stack.push(5)
    actual = new_stack.top.value
    expected = 5
    assert actual == expected
Ejemplo n.º 8
0
def test_new_stack():
    new_stack = Stack()
    assert new_stack
def test_seven_peek():
    initial_stack = Stack()
    with pytest.raises(Exception):
        initial_stack.peek()
def test_one():
    initial_stack = Stack()
    initial_stack.push("a")
    actual = initial_stack.top.value
    expected = "a"
    assert actual == expected
def test_six():
    initial_stack = Stack()
    actual = initial_stack.top
    expected = None
    assert actual == expected