Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #23 from JuliaGraphs/sbromberger/newshow
Browse files Browse the repository at this point in the history
change show() for empty graphs (ref https://github.com/JuliaGraphs/Me…
  • Loading branch information
sbromberger authored Jan 23, 2018
2 parents 558c7bb + c7afe2c commit 17334c4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/MetaGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ abstract type AbstractMetaGraph{T} <: AbstractGraph{T} end

function show(io::IO, g::AbstractMetaGraph)
dir = is_directed(g) ? "directed" : "undirected"
if nv(g) == 0
print(io, "empty $dir $(eltype(g)) metagraph with $(weighttype(g)) weights defined by :$(g.weightfield) (default weight $(g.defaultweight))")
else
print(io, "{$(nv(g)), $(ne(g))} $dir $(eltype(g)) metagraph with $(weighttype(g)) weights defined by :$(g.weightfield) (default weight $(g.defaultweight))")
end
print(io, "{$(nv(g)), $(ne(g))} $dir $(eltype(g)) metagraph with $(weighttype(g)) weights defined by :$(g.weightfield) (default weight $(g.defaultweight))")
end

@inline fadj(g::AbstractMetaGraph, x...) = fadj(g.graph, x...)
Expand Down
4 changes: 2 additions & 2 deletions test/metagraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ importall MetaGraphs
mg = MetaGraph(g)
T = eltype(mg)
U = weighttype(mg)
@test sprint(show, mg) == "empty undirected $T metagraph with $U weights defined by :$(mg.weightfield) (default weight $(mg.defaultweight))"
@test sprint(show, mg) == "{0, 0} undirected $T metagraph with $U weights defined by :$(mg.weightfield) (default weight $(mg.defaultweight))"
@test @inferred(add_vertices!(g, 5)) == 5
@test sprint(show, mg) == "{5, 0} undirected $T metagraph with $U weights defined by :$(mg.weightfield) (default weight $(mg.defaultweight))"
end
Expand All @@ -154,7 +154,7 @@ importall MetaGraphs
mg = MetaDiGraph(g)
T = eltype(mg)
U = weighttype(mg)
@test sprint(show, mg) == "empty directed $T metagraph with $U weights defined by :$(mg.weightfield) (default weight $(mg.defaultweight))"
@test sprint(show, mg) == "{0, 0} directed $T metagraph with $U weights defined by :$(mg.weightfield) (default weight $(mg.defaultweight))"
@test @inferred(add_vertices!(mg, 5)) == 5
@test sprint(show, mg) == "{5, 0} directed $T metagraph with $U weights defined by :$(mg.weightfield) (default weight $(mg.defaultweight))"
end
Expand Down

0 comments on commit 17334c4

Please sign in to comment.