Exemple #1
0
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
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
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
Exemple #6
0
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
Exemple #7
0
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
Exemple #8
0
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
Exemple #9
0
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
Exemple #10
0
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
Exemple #11
0
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
Exemple #12
0
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)