Example #1
0
def test_remove_node(num_nodes, idx_to_remove, expected_adj):
    my_graph = Graph(f'gr{num_nodes}', f'gr{num_nodes}.gxl', num_nodes)
    nodes = []

    for i in range(num_nodes):
        tmp_node = Node(i, LabelNodeLetter(1+i, 1))
        nodes.append(tmp_node)
        my_graph.add_node(tmp_node)

    for idx_start, idx_end in combinations(range(num_nodes), 2):
        tmp_edge = Edge(idx_start, idx_end, LabelEdge(0))
        my_graph.add_edge(tmp_edge)

    my_graph.remove_node_by_idx(idx_to_remove)
    # nodes.pop(0)

    # expected edges
    # expected_adjacency_mat = np.array([[0, 1, 1],
    #                                    [1, 0, 1],
    #                                    [1, 1, 0]])

    print(f'--{nodes}')
    print(my_graph.get_nodes())
    # assert my_graph.get_nodes() == nodes
    assert len(my_graph) == num_nodes - 1
Example #2
0
def test_add_node(num_nodes):
    my_graph = Graph(f'gr{num_nodes}', f'gr{num_nodes}.gxl', num_nodes)
    nodes = []

    for i in range(num_nodes):
        tmp_node = Node(i, LabelNodeLetter(1, 1))
        nodes.append(tmp_node)
        my_graph.add_node(tmp_node)

    assert my_graph.get_nodes() == nodes
    assert len(my_graph) == num_nodes