|
354 | 354 | end |
355 | 355 | end |
356 | 356 |
|
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 |
360 | 360 | g = cycle_graph(n) |
361 | | - lg = line_graph(g) |
| 361 | + lg = line_graph(g) # checking if lg is an n-cycle |
362 | 362 | @test nv(lg) == n |
363 | 363 | @test ne(lg) == n |
364 | 364 | @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)) |
366 | 366 | end |
367 | 367 | end |
368 | 368 |
|
369 | | - @testset "Path Graphs" begin |
370 | | - for n in 2:5 |
| 369 | + @testset "Undirected Path Graphs" begin |
| 370 | + for n in 2:9 |
371 | 371 | 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 |
375 | 375 | @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 |
379 | 378 | end |
380 | 379 | end |
381 | 380 |
|
382 | | - @testset "Star Graphs" begin |
383 | | - for n in 3:5 |
| 381 | + @testset "Undirected Star Graphs" begin |
| 382 | + for n in 3:9 |
384 | 383 | 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 |
390 | 387 | end |
391 | 388 | 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 |
392 | 396 | end |
0 commit comments