Skip to content

Commit

Permalink
NamedGraph conversion (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Apr 26, 2024
1 parent 2bf4239 commit 0feb539
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/namedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,27 @@ end

GenericNamedGraph() = GenericNamedGraph(Any[])

function GenericNamedGraph(graph::GenericNamedGraph)
return GenericNamedGraph{vertextype(graph),position_graph_type(graph_type)}(graph)
end
function GenericNamedGraph{V}(graph::GenericNamedGraph) where {V}
return GenericNamedGraph{V,position_graph_type(graph_type)}(graph)
end
function GenericNamedGraph{<:Any,G}(
graph::GenericNamedGraph
) where {G<:AbstractSimpleGraph{Int}}
return GenericNamedGraph{vertextype(graph),G}(graph)
end
function GenericNamedGraph{V,G}(
graph::GenericNamedGraph
) where {V,G<:AbstractSimpleGraph{Int}}
return GenericNamedGraph{V,G}(copy(position_graph(graph)), copy(vertices(graph)))
end

function Base.convert(graph_type::Type{<:GenericNamedGraph}, graph::GenericNamedGraph)
return graph_type(graph)
end

# TODO: implement as:
# graph = set_position_graph(graph, copy(position_graph(graph)))
# graph = set_vertices(graph, copy(vertices(graph)))
Expand Down
16 changes: 16 additions & 0 deletions test/test_namedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ end
rem_vertex!(g, "E")
@test !has_vertex(g, "E")

g = NamedGraph(grid((4,)), ["A", "B", "C", "D"])
for gc in (NamedGraph(g), convert(NamedGraph, g))
@test gc == g
@test gc isa NamedGraph{String}
@test vertextype(gc) === vertextype(g)
@test issetequal(vertices(gc), vertices(g))
@test issetequal(edges(gc), edges(g))
end
for gc in (NamedGraph{Any}(g), convert(NamedGraph{Any}, g))
@test gc == g
@test gc isa NamedGraph{Any}
@test vertextype(gc) === Any
@test issetequal(vertices(gc), vertices(g))
@test issetequal(edges(gc), edges(g))
end

io = IOBuffer()
show(io, "text/plain", g)
@test String(take!(io)) isa String
Expand Down

2 comments on commit 0feb539

@mtfishman
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/105681

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.0 -m "<description of version>" 0feb5396d9aa0142cd4292f138ccf17d83f8339b
git push origin v0.6.0

Please sign in to comment.