Skip to content

Commit

Permalink
Extend union to multiple named graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Feb 12, 2024
2 parents c93c030 + 6c2cf10 commit f2dbd17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/abstractnamedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,15 @@ function union(graph1::AbstractNamedGraph, graph2::AbstractNamedGraph)
return union_graph
end

function union(
graph1::AbstractNamedGraph,
graph2::AbstractNamedGraph,
graph3::AbstractNamedGraph,
graph_rest::AbstractNamedGraph...,
)
return union(union(graph1, graph2), graph3, graph_rest...)
end

function rem_vertex!(graph::AbstractNamedGraph, vertex)
if vertex vertices(graph)
return false
Expand Down
9 changes: 9 additions & 0 deletions test/test_multidimgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ using Test
@test has_vertex(g, ((1, 1), "X"))
@test has_vertex(g, ((1, 1), "Y"))

g3 = NamedGraph(grid((2, 2)); vertices=(2, 2))
g = disjoint_union("X" => g1, "Y" => g2, "Z" => g3)

@test nv(g) == 12
@test ne(g) == 12
@test has_vertex(g, ((1, 1), "X"))
@test has_vertex(g, ((1, 1), "Y"))
@test has_vertex(g, ((1, 1), "Z"))

# TODO: Need to drop the dimensions to make these equal
#@test issetequal(Graphs.vertices(g1), Graphs.vertices(g["X", :]))
#@test issetequal(edges(g1), edges(g["X", :]))
Expand Down

0 comments on commit f2dbd17

Please sign in to comment.