예제 #1
0
def test_exhausted():
    q = Queue()
    q.enqueue("apple")
    q.enqueue("banana")
    q.dequeue()
    q.dequeue()
    assert q.is_empty() == True
def test_exhausted():
    q = Queue()
    q.enqueue("apples")
    q.enqueue("orange")
    q.dequeue()
    q.dequeue()
    actual = q.is_empty()
    expected = True
    assert actual == expected
예제 #3
0
def test_exhausted():
    q = Queue()
    q.enqueue("apple")
    q.enqueue("banana")
    q.enqueue("cucumber")
    q.dequeue()
    q.dequeue()
    q.dequeue()
    actual = q.is_empty()
    expected = True
    assert actual == expected
예제 #4
0
 def breadth_first(self) -> list:
     breadth_queue = Queue()
     output = []
     breadth_queue.enqueue(self.root)
     while not breadth_queue.is_empty():
         front = breadth_queue.dequeue()
         output.append(front.value)
         if front.left:
             breadth_queue.enqueue(front.left)
         if front.right:
             breadth_queue.enqueue(front.right)
     return output
예제 #5
0
def test_dequeue_empty():
    queue = Queue()
    queue.enqueue('Dennis')
    queue.enqueue('Mac')
    queue.enqueue('Charlie')
    queue.enqueue('Dee')
    queue.dequeue()
    queue.dequeue()
    queue.dequeue()
    queue.dequeue()
    actual = queue.is_empty()
    expected = True
    assert actual == expected
예제 #6
0
    def breadth_traverse(self):
        if not self.root:
            raise Exception('tree is empty')

        output = []
        q = Queue()
        q.enqueue(self.root)
        while not q.is_empty():
            current = q.dequeue()
            if current.left:
                q.enqueue(current.left)
            if current.right:
                q.enqueue(current.right)
            output.append(current.value)
        return output
    def breadth_first(self, node):
        visited = [node]

        q = Queue()
        q.enqueue(node)

        while not q.is_empty():
            node = q.dequeue()

            neighbors = [edge.vertex for edge in self.get_neighbors(node)]

            for neighbor in neighbors:
                if neighbor not in visited:
                    visited.append(neighbor)
                    q.enqueue(neighbor)

        return visited
예제 #8
0
def test_is_empty():
    q = Queue()
    assert q.is_empty() == True
예제 #9
0
def test_is_empty():
    q = Queue()
    actual = q.is_empty()
    expected = True
    assert actual == expected
예제 #10
0
def test_new_queue():
    queue = Queue()
    actual = queue.is_empty()
    expected = True
    assert actual == expected