@@ -26,7 +26,7 @@ using Graphs:
2626using Graphs. SimpleGraphs: SimpleDiGraph, SimpleEdge, SimpleGraph
2727using GraphsFlows: GraphsFlows
2828using NamedGraphs: NamedDiGraph, NamedEdge, NamedGraph
29- using NamedGraphs. GraphsExtensions: ⊔ , rename_vertices, vertextype
29+ using NamedGraphs. GraphsExtensions: ⊔ , rename_vertices, subgraph, vertextype
3030using NamedGraphs. NamedGraphGenerators: named_grid, named_path_graph
3131using NamedGraphs. OrdinalIndexing: nd, st, rd, th
3232using Test: @test , @test_broken , @testset
@@ -193,6 +193,40 @@ using Test: @test, @test_broken, @testset
193193 @test dg[1 => 2 ] == :default
194194 end
195195
196+ @testset " subgraph" begin
197+ dg = DataGraph (named_path_graph (4 ))
198+ dg[1 ] = " V1"
199+ dg[2 ] = " V2"
200+ dg[3 ] = " V3"
201+ dg[4 ] = " V4"
202+ dg[1 => 2 ] = " E12"
203+ dg[2 => 3 ] = " E23"
204+ dg[3 => 4 ] = " E34"
205+ sg = subgraph (dg, [2 , 3 , 4 ])
206+ @test nv (sg) == 3
207+ @test ne (sg) == 2
208+ @test ! has_vertex (sg, 1 )
209+ @test has_vertex (sg, 2 )
210+ @test has_vertex (sg, 3 )
211+ @test has_vertex (sg, 4 )
212+ @test ! has_edge (sg, 1 => 2 )
213+ @test ! has_edge (sg, 2 => 1 )
214+ @test has_edge (sg, 2 => 3 )
215+ @test has_edge (sg, 3 => 2 )
216+ @test has_edge (sg, 3 => 4 )
217+ @test has_edge (sg, 4 => 3 )
218+ @test isnothing (get (sg, 1 , nothing ))
219+ @test sg[2 ] == " V2"
220+ @test sg[3 ] == " V3"
221+ @test sg[4 ] == " V4"
222+ @test isnothing (get (sg, 1 => 2 , nothing ))
223+ @test isnothing (get (sg, 2 => 1 , nothing ))
224+ @test sg[2 => 3 ] == " E23"
225+ @test sg[3 => 2 ] == " E23"
226+ @test sg[3 => 4 ] == " E34"
227+ @test sg[4 => 3 ] == " E34"
228+ end
229+
196230 @testset " Constructors specifying vertex type" begin
197231 dg = DataGraph {Float64} (
198232 named_path_graph (4 ); vertex_data_eltype = String, edge_data_eltype = Symbol
0 commit comments