Skip to content

Commit d4603ae

Browse files
committed
corrected the tests for undirected line graph
1 parent 78081ca commit d4603ae

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ benchmark/Manifest.toml
1414
/docs/src/index.md
1515
/docs/src/contributing.md
1616
/docs/src/license.md
17+
.aider*

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ArnoldiMethod = "ec485272-7323-5ecc-a04f-4719b315124d"
77
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
88
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
99
Inflate = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9"
10+
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
1011
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1112
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1213
SharedArrays = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

test/operators.jl

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -354,39 +354,43 @@
354354
end
355355
end
356356

357-
@testset "Line Graph" begin
358-
@testset "Cycle Graphs" begin
359-
for n in 3:5
357+
@testset "Undirected Line Graph" begin
358+
@testset "Undirected Cycle Graphs" begin
359+
for n in 3:9
360360
g = cycle_graph(n)
361-
lg = line_graph(g)
361+
lg = line_graph(g) # checking if lg is an n-cycle
362362
@test nv(lg) == n
363363
@test ne(lg) == n
364364
@test is_connected(lg)
365-
@test all(degree(lg) .== 2) # All vertices degree 2
365+
@test all(degree(lg, v) == 2 for v in vertices(lg))
366366
end
367367
end
368368

369-
@testset "Path Graphs" begin
370-
for n in 2:5
369+
@testset "Undirected Path Graphs" begin
370+
for n in 2:9
371371
g = path_graph(n)
372-
lg = line_graph(g)
373-
@test nv(lg) == n-1
374-
@test ne(lg) == n-2
372+
lg = line_graph(g) # checking if lg is an n-1-path
373+
@test nv(lg) == n - 1
374+
@test ne(lg) == n - 2
375375
@test is_connected(lg)
376-
degrees = degree(lg)
377-
@test sum(degrees .== 1) == 2 # Exactly 2 leaves
378-
@test sum(degrees .== 2) == max(0, n-3) # Rest degree 2
376+
@test all(degree(lg, v) <= 2 for v in vertices(lg))
377+
@test any(degree(lg, v) == 1 for v in vertices(lg)) || n == 2 && ne(lg) == 0
379378
end
380379
end
381380

382-
@testset "Star Graphs" begin
383-
for n in 3:5
381+
@testset "Undirected Star Graphs" begin
382+
for n in 3:9
384383
g = star_graph(n)
385-
lg = line_graph(g)
386-
@test nv(lg) == n-1
387-
@test ne(lg) == binomial(n-1, 2) # Complete graph edge count
388-
@test is_connected(lg)
389-
@test all(degree(lg) .== n-2) # Regular graph of degree n-2
384+
lg = line_graph(g) # checking if lg is a complete graph on n-1 vertices
385+
@test nv(lg) == n - 1
386+
@test ne(lg) == binomial(n - 1, 2) # lg must be a complete graph
390387
end
391388
end
389+
390+
@testset "Self-loops" begin
391+
g = SimpleGraph(2, [[2], [1, 2], Int[]])
392+
lg = line_graph(g)
393+
@test nv(lg) == 2 # only 2 edges (self-loop counts once)
394+
@test ne(lg) == 1 # only connection between edge 1-2 and self-loop 2-2
395+
end
392396
end

0 commit comments

Comments
 (0)