def test_breadth_first_regular(): graph = Graph() banana = graph.add_node('banana') vertices_lst = graph.breadth_first(banana) apple = graph.add_node('apple') graph.add_edge(banana, apple) vertices_lst = graph.breadth_first(banana) assert vertices_lst == [banana, apple]
def test_breadth_first_one_element(): graph = Graph() banana = graph.add_node('banana') vertices_lst = graph.breadth_first(banana) assert vertices_lst == [banana]
def test_breadth_first_empty_graph(): graph = Graph() banana = Vertex("banana") with pytest.raises(ValueError): vertices_lst = graph.breadth_first(banana)
def test_breadth_firts_islands_nodes(): graph = Graph() banana = graph.add_node('banana') apple = graph.add_node('apple') strawberry = graph.add_node('strawberry') graph.add_edge(banana, apple) vertices_lst = graph.breadth_first(banana) assert vertices_lst == [banana, apple] vertices_lst = graph.breadth_first(apple) assert vertices_lst == [apple]
def test_breadth_first_check_visited(): graph = Graph() banana = graph.add_node('banana') apple = graph.add_node('apple') strawberry = graph.add_node('strawberry') graph.add_edge(banana, apple) graph.add_edge(apple, strawberry) vertices_lst = graph.breadth_first(banana) assert vertices_lst == [banana, apple, strawberry] tomato = graph.add_node('tomato') graph.add_edge(apple, tomato) vertices_lst = graph.breadth_first(banana) assert vertices_lst == [banana, apple, strawberry, tomato]
def test_breadth_first_regular2(): graph = Graph() banana = graph.add_node('banana') apple = graph.add_node('apple') strawberry = graph.add_node('strawberry') graph.add_edge(banana, apple) graph.add_edge(strawberry, banana) vertices_lst = graph.breadth_first(strawberry) assert vertices_lst == [strawberry, banana, apple]
def test_breadth_first_different_start_node(): graph = Graph() banana = graph.add_node('banana') apple = graph.add_node('apple') strawberry = graph.add_node('strawberry') graph.add_edge(banana, apple) graph.add_edge(strawberry, banana) vertices_lst = graph.breadth_first(banana) assert vertices_lst == [banana, apple]
def test_breadth_first(): graph = Graph() # add all nodes apple = graph.add_node('apple') banana = graph.add_node('banana') cantelope = graph.add_node('cantelope') dates = graph.add_node('dates') eggplant = graph.add_node('eggplant') figs = graph.add_node('figs') # add all edges graph.add_edge(apple, banana, 1) graph.add_edge(banana, apple, 2) graph.add_edge(banana, cantelope, 3) graph.add_edge(banana, figs, 4) graph.add_edge(cantelope, banana, 5) graph.add_edge(cantelope, figs, 6) graph.add_edge(cantelope, dates, 7) graph.add_edge(figs, banana, 8) graph.add_edge(figs, cantelope, 9) graph.add_edge(figs, dates, 10) graph.add_edge(figs, eggplant, 20) graph.add_edge(dates, cantelope, 30) graph.add_edge(dates, figs, 40) graph.add_edge(dates, eggplant, 50) graph.add_edge(eggplant, figs, 60) graph.add_edge(eggplant, dates, 70) assert graph.breadth_first(apple) == { apple, dates, eggplant, cantelope, figs, banana }