Пример #1
0
def test_Stack_push():
    stack = Stack()
    stack.push(5)
    stack.push(6)
    actual=stack.peek()
    expexted=6
    assert actual==expexted
Пример #2
0
def test_pop_empty():
    stack = Stack()
    stack.push(33)
    stack.push(5)
    stack.pop()
    stack.pop()
    assert stack.isEmpty() == True
Пример #3
0
def test_three_stack():
    fruites = Stack()
    fruites.push('Orange')
    fruites.push('Pineapple')
    fruites.push('Berry')
    expected = 'Berry'
    actual = fruites.pop()
    assert expected == actual
Пример #4
0
def depth_first(self, starting_vertex):
    vertices = []
    depth = Stack()

    if starting_vertex not in self._adjacency_list:
        raise ValueError

    depth.push(starting_vertex)

    while not depth.is_empty():
        top_vertex = depth.pop()
        vertices.append(top_vertex.value)
        top_node_neighbors = self.get_neighbors(top_vertex)

        for neighbor in top_node_neighbors[::-1]:
            if not neighbor[0].visited:
                top_vertex.visited = True
                neighbor[0].visited = True

                depth.push(neighbor[0])

    for node in self._adjacency_list:
        node.visited = False

    return vertices
Пример #5
0
def test_one_stack():
    fruites = Stack()
    fruites.push('Orange')
    fruites.push('Pineapple')
    fruites.push('Berry')
    expected = ['Orange', 'Pineapple', 'Berry']
    actual = fruites.items
    assert expected == actual
Пример #6
0
def test_stack_push():

    test_stack = Stack()
    assert test_stack.top == None
    test_stack.push(5)
    assert test_stack.top.value == 5
    test_stack.push('b')
    assert test_stack.top.value == 'b'
    test_stack.push('c')
    assert test_stack.top.value == 'c'
Пример #7
0
class PseudoQueue():
    def __init__(self):
        self.front_stack = Stack()
        self.rear_stack = Stack()
        self.len = 0

    def enqueue(self, info):
        inputs = self.front_stack
        self.len += 1
        if info == None:
            return 'Not a valid input'
        inputs.push(info)
        return inputs

    def dequeue(self):
        if self.rear_stack.is_empty():
            while self.len > 0:
                self.rear_stack.push(self.front_stack.pop())
                self.len -= 1
            output = self.rear_stack.pop()

            while True:
                self.front_stack.push(self.rear_stack.pop())
                self.len += 1
                if self.rear_stack.is_empty():
                    return output

        else:
            return 'The stack is empty'

    def __str__(self):
        output = 'Rear -> '
        if self.front_stack.is_empty():
            current = self.rear_stack.top
        else:
            current = self.front_stack.top
        while current:
            output += f"{{{current.info}}} -> "
            current = current.next
        output += "Front"
        return output
class PseudoQueue:
    def __init__(self):
        self.stack1 = Stack()
        self.stack2 = Stack()
        self.rear = 0
        

    def enqueue(self,*value):
        self.stack1.push(*value)
        self.rear = self.stack1.top.value

    def dequeue(self):
        if self.stack1.is_empty() and self.stack2.is_empty():
            return 'empty queue !!!'
        elif self.stack2.is_empty():
            while self.stack1.top:
                self.stack2.push(self.stack1.pop())
        return self.stack2.pop()
Пример #9
0
def test_stack_init():
    stack = Stack()
    assert stack.top == None
Пример #10
0
def test_stack_peek():
    stack = Stack()
    stack.push(33)
    stack.push(5)
    assert stack.peek() == 5
Пример #11
0
def test_push():
    stack = Stack()
    stack.push(5)
    actual = stack.top.value
    expected = 5
    assert actual == expected
Пример #12
0
def test_pop():
    stack = Stack()
    stack.push(33)
    stack.push(5)
    stack.pop()
    assert stack.top.data == 33
Пример #13
0
def test_isEmpty_Stack():
    stack = Stack()
    stack.is_empty()
    actual = stack.top
    expected = None
    assert actual == expected
Пример #14
0
def test_Stack_is_empty():
    stack = Stack()
    actual= stack.is_empty()
    expexted=True
    assert actual==expexted
Пример #15
0
def  test_empty_stack():
    ''' Calling dequeue or peek on empty queue raises exception'''
    stack = Stack()
    assert stack.peek()=='Empty stack'
Пример #16
0
def create_stack(nodes):
    """helper function to create a stack"""
    test_stack = Stack()
    for el in nodes:
        test_stack.push(el)
    return test_stack
Пример #17
0
def test_stack_empty():
    test_stack = Stack()
    assert test_stack.top == None
Пример #18
0
def test_queue_is_empty():
    test_queue = create_queue(['a', 'b', 'c', 'd'])
    assert test_queue.is_empty() == False
    test_queue = Stack()
    assert test_queue.is_empty() == True
Пример #19
0
def test_stack_empty_exception():
    stack = Stack()
    with pytest.raises(Exception):
        assert stack.pop()
    with pytest.raises(Exception):
        assert stack.peek()
Пример #20
0
def test_stack_is_empty():
    test_stack = create_stack(['a', 'b', 'c', 'd'])
    assert test_stack.is_empty() == False
    test_stack = Stack()
    assert test_stack.is_empty() == True
def data():
    new_stack = Stack()
    new_queue = Queue()
    return {'stack': new_stack, 'queue': new_queue}
Пример #22
0
class PseudoQueue:
    def __init__(self):
        self.stack_one = Stack()
        self.stack_two = Stack()
        self.count = 0

    def enqueue(self, *data):
        self.count += 1 
        for i in data:
            self.stack_one.push(i)

    def dequeue(self):
        if self.stack_two.isEmpty():
            while self.count > 0:
                self.stack_two.push(self.stack_one.pop())
                self.count-=1
            self.stack_two.pop()
            while True:
                self.stack_one.push(self.stack_two.pop())
                self.count +=1
                if self.stack_two.isEmpty():
                    return self.stack_two.pop()
        else:
            return "stack is empty!"

    def __str__(self):
        result = ''
        if self.stack_one.isEmpty():
            current = self.stack_two.top
        else:
            current = self.stack_one.top
        while current:
            result += f"{{{current.data}}} -> "
            current = current.next
        return result
Пример #23
0
 def __init__(self):
     self.stack_one = Stack()
     self.stack_two = Stack()
     self.count = 0
Пример #24
0
def prep_stack():
    stack = Stack()
    stack.push(1)
    stack.push(2)
    stack.push(3)
    return stack
Пример #25
0
def test_push_one():
    stack = Stack()
    stack.push(33)
    assert stack.top.data == 33
Пример #26
0
 def __init__(self):
     self.front_stack = Stack()
     self.rear_stack = Stack()
     self.len = 0
Пример #27
0
def test_push_multiple():
    stack = Stack()
    stack.push(33)
    stack.push(5)
    assert stack.top.data == 5
 def __init__(self):
     self.stack1 = Stack()
     self.stack2 = Stack()
     self.rear = 0
def fixed_stack():
    s_stack = Stack()
    s_stack.push(9)
    s_stack.push(7)
    s_stack.push(5)
    return s_stack