@@ -334,14 +334,25 @@ using SparseArrays
334334 # this testset was implemented for https://github.com/JuliaGraphs/SimpleWeightedGraphs.jl/issues/32
335335 @testset " induced_subgraph should preserve weights for edge lists" begin
336336 g = SimpleWeightedGraph ([0 2 ; 2 0 ])
337- graphWeights = weights (g)
338- expectedGraphWeights = sparse ([0 2 ; 2 0 ])
339- @test graphWeights == expectedGraphWeights
337+ expected_graph_weights = sparse ([0 2 ; 2 0 ])
340338 # vertex induced subgraph
341- vertexInducedSubgraphWeights = weights (first (induced_subgraph (g, [1 , 2 ])))
342- @test vertexInducedSubgraphWeights == expectedGraphWeights
339+ vertex_induced_subgraph_weights = weights (first (induced_subgraph (g, [1 , 2 ])))
340+ @test vertex_induced_subgraph_weights == expected_graph_weights
343341 # edge induced subgraph
344- edgeInducedSubgraphWeights = weights (first (induced_subgraph (g, [Edge (1 , 2 )])))
345- @test edgeInducedSubgraphWeights == expectedGraphWeights
342+ edge_induced_subgraph_weights = weights (first (induced_subgraph (g, [Edge (1 , 2 )])))
343+ @test edge_induced_subgraph_weights == expected_graph_weights
344+
345+ # test edge induced graph with one edge removed
346+ # graph isomorphic to C_5
347+ g = SimpleWeightedGraph ([0 2 0 0 2 ; 2 0 2 0 0 ; 0 2 0 2 0 ; 0 0 2 0 2 ; 2 0 0 2 0 ])
348+ expected_graph_weights = sparse ([0 2 0 0 0 ; 2 0 2 0 0 ; 0 2 0 2 0 ; 0 0 2 0 2 ; 0 0 0 2 0 ]);
349+ # create edge induced subgraph isomorphic to P_5. The edge (1, 5) is missing and test if weights are correct.
350+ edge_induced_subgraph_weights = weights (first (induced_subgraph (g, [Edge (1 , 2 ), Edge (2 , 3 ), Edge (3 , 4 ), Edge (4 , 5 )])))
351+ @test edge_induced_subgraph_weights == expected_graph_weights
352+
353+ # test edge induced subgraph which does not contain the whole vertex set, especially remove the first column (vertex 1)
354+ edge_induced_subgraph_weights = weights (first (induced_subgraph (g, [Edge (2 , 3 )])))
355+ expected_graph_weights = sparse ([0 2 ; 2 0 ])
356+ @test edge_induced_subgraph_weights == expected_graph_weights
346357 end
347358end
0 commit comments