Skip to content

Commit 1b3282b

Browse files
committed
I notice there seems to be some confusion in the diffs - the new tests were added in the wrong location (before the "Undirected Line Graph" tests instead of after). Let me correct that:
test/operators.jl ```julia <<<<<<< SEARCH @testset "Length: $(typeof(g))" for g in test_generic_graphs(SimpleGraph(100)) @test length(g) == 10000 end end @testset "Undirected Line Graph" begin ======= @testset "Length: $(typeof(g))" for g in test_generic_graphs(SimpleGraph(100)) @test length(g) == 10000 end end @testset "Directed Line Graph" begin @testset "Directed Cycle Graphs" begin for n in 3:9 g = cycle_digraph(n) lg = line_graph(g) @test nv(lg) == n @test ne(lg) == n @test is_directed(lg) @test all(outdegree(lg, v) == 1 for v in vertices(lg)) @test all(indegree(lg, v) == 1 for v in vertices(lg)) end end @testset "Directed Path Graphs" begin for n in 2:9 g = path_digraph(n) lg = line_graph(g) @test nv(lg) == n - 1 @test ne(lg) == n - 2 @test is_directed(lg) @test is_connected(lg) @test all(outdegree(lg, v) <= 1 for v in vertices(lg)) @test all(indegree(lg, v) <= 1 for v in vertices(lg)) if n > 2 @test indegree(lg, 1) == 0 @test outdegree(lg, 1) == 1 @test indegree(lg, nv(lg)) == 1 @test outdegree(lg, nv(lg)) == 0 end end end @testset "Directed Star Graphs" begin for n in 3:9 g = star_digraph(n) lg = line_graph(g) @test nv(lg) == n - 1 @test ne(lg) == 0 end for n in 3:9 g = SimpleDiGraph(n) for i in 2:n add_edge!(g, 1, i) add_edge!(g, i, 1) end lg = line_graph(g) @test nv(lg) == 2*(n-1) @test ne(lg) == (n-1) + (n-1)*(n-1) end end @testset "Directed Self-loops" begin g = SimpleDiGraph(2) add_edge!(g, 1, 1) add_edge!(g, 1, 2) lg = line_graph(g) @test nv(lg) == 2 @test ne(lg) == 2 @test has_edge(lg, 1, 1) @test has_edge(lg, 1, 2) @test !has_edge(lg, 2, 1) @test !has_edge(lg, 2, 2) end end @testset "Undirected Line Graph" begin >>>>>>> REPLACE ``` This change: 1. Adds the new directed line graph tests in the correct location (after the length tests and before the undirected line graph tests) 2. Maintains all existing tests exactly as they were 3. Adds comprehensive tests for directed line graphs with the same structure as the undirected tests The tests cover: - Directed cycle graphs (should produce directed cycles) - Directed path graphs (should produce shorter directed paths) - Directed star graphs (both unidirectional and bidirectional cases) - Directed graphs with self-loops (testing edge cases) Each test verifies the expected number of vertices, edges, and connectivity properties of the resulting line graph.
1 parent 4de39c5 commit 1b3282b

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

test/operators.jl

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,71 @@
352352
@testset "Length: $(typeof(g))" for g in test_generic_graphs(SimpleGraph(100))
353353
@test length(g) == 10000
354354
end
355+
@testset "Directed Line Graph" begin
356+
@testset "Directed Cycle Graphs" begin
357+
for n in 3:9
358+
g = cycle_digraph(n)
359+
lg = line_graph(g)
360+
@test nv(lg) == n
361+
@test ne(lg) == n
362+
@test is_directed(lg)
363+
@test all(outdegree(lg, v) == 1 for v in vertices(lg))
364+
@test all(indegree(lg, v) == 1 for v in vertices(lg))
365+
end
366+
end
367+
368+
@testset "Directed Path Graphs" begin
369+
for n in 2:9
370+
g = path_digraph(n)
371+
lg = line_graph(g)
372+
@test nv(lg) == n - 1
373+
@test ne(lg) == n - 2
374+
@test is_directed(lg)
375+
@test is_connected(lg)
376+
@test all(outdegree(lg, v) <= 1 for v in vertices(lg))
377+
@test all(indegree(lg, v) <= 1 for v in vertices(lg))
378+
if n > 2
379+
@test indegree(lg, 1) == 0
380+
@test outdegree(lg, 1) == 1
381+
@test indegree(lg, nv(lg)) == 1
382+
@test outdegree(lg, nv(lg)) == 0
383+
end
384+
end
385+
end
386+
387+
@testset "Directed Star Graphs" begin
388+
for n in 3:9
389+
g = star_digraph(n)
390+
lg = line_graph(g)
391+
@test nv(lg) == n - 1
392+
@test ne(lg) == 0
393+
end
394+
395+
for n in 3:9
396+
g = SimpleDiGraph(n)
397+
for i in 2:n
398+
add_edge!(g, 1, i)
399+
add_edge!(g, i, 1)
400+
end
401+
lg = line_graph(g)
402+
@test nv(lg) == 2*(n-1)
403+
@test ne(lg) == (n-1) + (n-1)*(n-1)
404+
end
405+
end
406+
407+
@testset "Directed Self-loops" begin
408+
g = SimpleDiGraph(2)
409+
add_edge!(g, 1, 1)
410+
add_edge!(g, 1, 2)
411+
lg = line_graph(g)
412+
@test nv(lg) == 2
413+
@test ne(lg) == 2
414+
@test has_edge(lg, 1, 1)
415+
@test has_edge(lg, 1, 2)
416+
@test !has_edge(lg, 2, 1)
417+
@test !has_edge(lg, 2, 2)
418+
end
419+
end
355420
end
356421

357422
@testset "Undirected Line Graph" begin
@@ -393,4 +458,6 @@ end
393458
@test nv(lg) == 2 # only 2 edges (self-loop counts once)
394459
@test ne(lg) == 1 # only connection between edge 1-2 and self-loop 2-2
395460
end
461+
462+
396463
end

0 commit comments

Comments
 (0)