def test_multiple_en_de_queues(self): items = [i for i in range(10)] for i in items: my_queue.enqueue(i) received_items = [] for _ in items: received_items.append(my_queue.dequeue()) self.assertEqual(items, received_items)
def bfs(g: nx.Graph, start_node: Hashable) -> List[Hashable]: """ Do an breadth-first search and returns list of nodes in the visited order :param g: input graph :param start_node: starting node for search :return: list of nodes in the visited order """ visited = [start_node] q.enqueue(start_node) while q.leng() > 0: start_node = q.dequeue() neighbors = list(g.neighbors(start_node)) for neigh in neighbors: if neigh not in visited: visited.append(neigh) q.enqueue(neigh) return visited
def bfs(g: nx.Graph, start_node: Hashable) -> List[Hashable]: """ Do an breadth-first search and returns list of nodes in the visited order :param g: input graph :param start_node: starting node for search :return: list of nodes in the visited order """ list_of_vizit = [] enqueue(start_node) list_of_vizit.append(start_node) while peek(0) != None: node_now = dequeue() neighbor_list = list(g.neighbors(node_now)) for i in neighbor_list: if i in list_of_vizit: pass else: enqueue(i) list_of_vizit.append(i) return list_of_vizit
def test_clear(self): my_queue.enqueue(3) my_queue.clear() self.assertIsNone(my_queue.dequeue())
def test_enqueue_dequeue(self): initial_elem = 3 my_queue.enqueue(initial_elem) self.assertEqual(initial_elem, my_queue.dequeue())