Skip to content

Commit e0619da

Browse files
committed
change show() for empty graphs (ref JuliaGraphs/MetaGraphs.jl#20 (comment))
1 parent b9f70b6 commit e0619da

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

src/StaticGraphs.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,8 @@ indtype(g::AbstractStaticGraph{T, U}) where T where U = U
5757
eltype(x::AbstractStaticGraph) = vectype(x)
5858

5959
function show(io::IO, g::AbstractStaticGraph)
60-
if is_directed(g)
61-
dir = "directed"
62-
else
63-
dir = "undirected"
64-
end
65-
if nv(g) == 0
66-
print(io, "empty $dir simple static {$(vectype(g)), $(indtype(g))} graph")
67-
else
68-
print(io, "{$(nv(g)), $(ne(g))} $dir simple static {$(vectype(g)), $(indtype(g))} graph")
69-
end
60+
dir = is_directed(g)? "directed" : "undirected"
61+
print(io, "{$(nv(g)), $(ne(g))} $dir simple static {$(vectype(g)), $(indtype(g))} graph")
7062
end
7163

7264
@inline function _fvrange(g::AbstractStaticGraph, s::Integer)

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const testdir = dirname(@__FILE__)
1212
dhu = loadgraph(joinpath(testdir, "testdata", "pathdg-uint8.jsg"), SDGFormat())
1313

1414
@testset "staticgraph" begin
15-
@test sprint(show, StaticGraph(Graph())) == "empty undirected simple static {UInt8, UInt8} graph"
15+
@test sprint(show, StaticGraph(Graph())) == "{0, 0} undirected simple static {UInt8, UInt8} graph"
1616
g = smallgraph(:house)
1717
gu = squash(g)
1818
sg = StaticGraph(g)
@@ -52,7 +52,7 @@ const testdir = dirname(@__FILE__)
5252
end # staticgraph
5353

5454
@testset "staticdigraph" begin
55-
@test sprint(show, StaticDiGraph(DiGraph())) == "empty directed simple static {UInt8, UInt8} graph"
55+
@test sprint(show, StaticDiGraph(DiGraph())) == "{0, 0} directed simple static {UInt8, UInt8} graph"
5656
dg = PathDiGraph(5)
5757
dgu = squash(dg)
5858
dsg = StaticDiGraph(dg)

0 commit comments

Comments
 (0)