Skip to content

Commit 8148c92

Browse files
committed
Fix bug in directed_graph calling removed similar_graph method; add tests.
1 parent 47620ed commit 8148c92

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/abstractdatagraph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ end
213213

214214
# Fallback to constructing a concrete `DataGraph`.
215215
@traitfn function GraphsExtensions.directed_graph(graph::AbstractDataGraph::(!IsDirected))
216-
underlying_digraph = similar_graph(NamedDiGraph, vertices(graph), edges(graph))
216+
underlying_digraph = similar_graph(NamedDiGraph, vertices(graph)) # edgeless
217217

218218
VD = vertex_data_type(graph)
219219
ED = edge_data_type(graph)

test/test_basics.jl

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ using Dictionaries: Dictionaries, AbstractDictionary, AbstractIndices, Dictionar
44
IndexError, Indices, dictionary, unset!
55
using Graphs: SimpleDiGraph, a_star, add_edge!, bfs_tree, connected_components, degree,
66
dfs_tree, dijkstra_shortest_paths, dst, edges, edgetype, grid, has_edge, has_vertex,
7-
indegree, ne, nv, outdegree, path_graph, src, steiner_tree, vertices
7+
indegree, is_directed, ne, nv, outdegree, path_graph, src, steiner_tree, vertices
88
using GraphsFlows: GraphsFlows
9-
using NamedGraphs.GraphsExtensions: rename_vertices, subgraph, vertextype,
9+
using NamedGraphs.GraphsExtensions: directed_graph, rename_vertices, subgraph, vertextype,
1010
using NamedGraphs.NamedGraphGenerators: named_grid, named_path_graph
1111
using NamedGraphs.OrdinalIndexing: nd, rd, st, th
1212
using NamedGraphs: NamedDiGraph, NamedEdge, NamedGraph, empty_graph, similar_graph
@@ -153,6 +153,32 @@ using Test: @test, @test_broken, @testset
153153
@test dg[2 => "Y"] == "edge_Y2"
154154
@test dg["Y" => 2] == "edge_Y2"
155155
end
156+
@testset "(un)directed graph" begin
157+
dg = DataGraph(named_path_graph(3))
158+
dg[1 => 2] = "edge_12"
159+
@test dg[1 => 2] == "edge_12"
160+
@test dg[2 => 1] == "edge_12"
161+
dg[2 => 1] = "edge_21"
162+
@test dg[1 => 2] == "edge_21"
163+
@test dg[2 => 1] == "edge_21"
164+
165+
dg = DataGraph(named_path_graph(3))
166+
167+
dg[1 => 2] = "edge_12"
168+
169+
ddg = directed_graph(dg)
170+
@test !is_directed(dg)
171+
@test is_directed(ddg)
172+
@test isassigned(ddg, 1 => 2)
173+
@test isassigned(ddg, 2 => 1)
174+
@test ddg[1 => 2] == ddg[2 => 1]
175+
176+
ddg[1 => 2] = "edge_12"
177+
ddg[2 => 1] = "edge_21"
178+
179+
@test ddg[1 => 2] == "edge_12"
180+
@test ddg[2 => 1] == "edge_21"
181+
end
156182

157183
@testset "get and get! functions" begin
158184
g = named_grid(4)

0 commit comments

Comments
 (0)