def test_assert_vertice_exists_two_not_in_range(): try: graph = GraphMatrix(3) graph.add_edge(-1, 3) assert False except ValueError: assert True
def test_eval(size, edges, start_vertice, expected): graph = GraphMatrix(size, digraph=True) for x, y, w in edges: graph.add_edge(x, y, weight=w) dijkstra = Dijkstra(graph) result = dijkstra.run(start_vertice) assert result == expected
def test_path(edges, size, begin, end, expected): graph = GraphMatrix(size) for edge in edges: graph.add_edge(edge[0], edge[1]) print(graph) print(begin) print(end) assert graph.has_path(begin, end) == expected
def add_edges(graph: GraphMatrix, edges_list: List[List[int]]) -> GraphMatrix: if len(edges_list[0]) == 3: for x, y, z in edges_list: graph.add_edge(x, y, weight=z) else: for x, y in edges_list: graph.add_edge(x, y) return graph
def test_number_of_edges(input, expected): graph = GraphMatrix(10) edges = [] for i in range(input): edge1 = random.randint(0, 9) edge2 = random.randint(0, 9) edge = sorted([edge1, edge2]) if edge not in edges: edges.append(edge) for edge in edges: graph.add_edge(edge[0], edge[1]) expected = len(edges) print(edges) print(graph) assert graph.number_of_edges() == expected
def test_edges_acessible(edges, size, expected): graph = GraphMatrix(size) for edge in edges: graph.add_edge(edge[0], edge[1]) assert graph.has_acessible_edges() == expected
def test_vertices_with_edges(edges, size, expected): graph = GraphMatrix(size) for edge in edges: graph.add_edge(edge[0], edge[1]) assert graph.vertices_with_edges() == expected
def test_euler_path(edges, size, expected): graph = GraphMatrix(size) for edge in edges: graph.add_edge(edge[0], edge[1]) assert graph.has_open_euler_path() == expected
def test_num_loops_graph(edges, expected): graph = GraphMatrix(3) for edge in edges: graph.add_edge(edge[0], edge[1]) assert graph.number_of_loops_graph() == expected
def test_max_degree(edges, expected): graph = GraphMatrix(3) for edge in edges: graph.add_edge(edge[0], edge[1]) assert graph.max_degree() == expected
def test_degree(edges, vertice, expected): graph = GraphMatrix(3) for edge in edges: graph.add_edge(edge[0], edge[1]) assert graph.degree(vertice) == expected
def test_neighbourhood(edges, vertice, expected): graph = GraphMatrix(3) for edge in edges: graph.add_edge(edge[0], edge[1]) assert graph.neighbourhood(vertice) == expected
def test_eval(size, edges, expected): graph = GraphMatrix(size, digraph=True) for x, y in edges: graph.add_edge(x, y) warshall = Warshall(graph) assert warshall.run() == expected
def test_num_edges(size_graph, edges): graph = GraphMatrix(size_graph, digraph=True) for edge in edges: graph.add_edge(edge[0], edge[1]) assert graph.number_of_edges() == len(edges)