|
352 | 352 | @testset "Length: $(typeof(g))" for g in test_generic_graphs(SimpleGraph(100)) |
353 | 353 | @test length(g) == 10000 |
354 | 354 | end |
| 355 | + |
| 356 | + @testset "Undirected Line Graph" begin |
| 357 | + @testset "Undirected Cycle Graphs" begin |
| 358 | + for n in 3:9 |
| 359 | + g = cycle_graph(n) |
| 360 | + lg = line_graph(g) # checking if lg is an n-cycle |
| 361 | + @test nv(lg) == n |
| 362 | + @test ne(lg) == n |
| 363 | + @test is_connected(lg) |
| 364 | + @test all(degree(lg, v) == 2 for v in vertices(lg)) |
| 365 | + end |
| 366 | + end |
| 367 | + |
| 368 | + @testset "Undirected Path Graphs" begin |
| 369 | + for n in 2:9 |
| 370 | + g = path_graph(n) |
| 371 | + lg = line_graph(g) # checking if lg is an n-1-path |
| 372 | + @test nv(lg) == n - 1 |
| 373 | + @test ne(lg) == n - 2 |
| 374 | + @test is_connected(lg) |
| 375 | + @test all(degree(lg, v) <= 2 for v in vertices(lg)) |
| 376 | + @test any(degree(lg, v) == 1 for v in vertices(lg)) || n == 2 && ne(lg) == 0 |
| 377 | + end |
| 378 | + end |
| 379 | + |
| 380 | + @testset "Undirected Star Graphs" begin |
| 381 | + for n in 3:9 |
| 382 | + g = star_graph(n) |
| 383 | + lg = line_graph(g) # checking if lg is a complete graph on n-1 vertices |
| 384 | + @test nv(lg) == n - 1 |
| 385 | + @test ne(lg) == binomial(n - 1, 2) # lg must be a complete graph |
| 386 | + end |
| 387 | + end |
| 388 | + |
| 389 | + @testset "Undirected Self-loops" begin |
| 390 | + g = SimpleGraph(2, [[2], [1, 2], Int[]]) |
| 391 | + lg = line_graph(g) |
| 392 | + @test nv(lg) == 2 # only 2 edges (self-loop counts once) |
| 393 | + @test ne(lg) == 1 # only connection between edge 1-2 and self-loop 2-2 |
| 394 | + end |
| 395 | + end |
| 396 | + |
355 | 397 | @testset "Directed Line Graph" begin |
356 | 398 | @testset "Directed Cycle Graphs" begin |
357 | 399 | for n in 3:9 |
|
360 | 402 | @test nv(lg) == n |
361 | 403 | @test ne(lg) == n |
362 | 404 | @test is_directed(lg) |
| 405 | + @test is_connected(lg) |
363 | 406 | @test all(outdegree(lg, v) == 1 for v in vertices(lg)) |
364 | 407 | @test all(indegree(lg, v) == 1 for v in vertices(lg)) |
365 | 408 | end |
|
373 | 416 | @test ne(lg) == n - 2 |
374 | 417 | @test is_directed(lg) |
375 | 418 | @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 |
| 419 | + @test all(outdegree(lg, v) == (v < n - 1 ? 1 : 0) for v in vertices(lg)) |
| 420 | + @test all(indegree(lg, v) == (v > 1 ? 1 : 0) for v in vertices(lg)) |
384 | 421 | end |
385 | 422 | end |
386 | 423 |
|
387 | 424 | @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) |
| 425 | + for m in 0:4, n in 0:4 |
| 426 | + g = SimpleDiGraph(m + n + 1) |
| 427 | + foreach(i -> add_edge!(g, i + 1, 1), 1:m) |
| 428 | + foreach(j -> add_edge!(g, 1, j + 1 + m), 1:n) |
| 429 | + lg = line_graph(g) # checking if lg is the complete bipartite digraph |
| 430 | + @test nv(lg) == m + n |
| 431 | + @test ne(lg) == m * n |
| 432 | + @test all(outdegree(lg, v) == 0 && indegree(lg, v) == m for v in 1:n) |
| 433 | + @test all( |
| 434 | + outdegree(lg, v) == n && indegree(lg, v) == 0 for v in (n + 1):(n + m) |
| 435 | + ) |
404 | 436 | end |
405 | 437 | end |
406 | 438 |
|
407 | 439 | @testset "Directed Self-loops" begin |
408 | | - g = SimpleDiGraph(2) |
409 | | - add_edge!(g, 1, 1) |
410 | | - add_edge!(g, 1, 2) |
| 440 | + g = SimpleDiGraph(2, [[1, 2], Int[], Int[]], [[1], [1], Int[]]) |
411 | 441 | lg = line_graph(g) |
412 | 442 | @test nv(lg) == 2 |
413 | | - @test ne(lg) == 2 |
414 | | - @test has_edge(lg, 1, 1) |
| 443 | + @test ne(lg) == 1 |
415 | 444 | @test has_edge(lg, 1, 2) |
416 | | - @test !has_edge(lg, 2, 1) |
417 | | - @test !has_edge(lg, 2, 2) |
418 | | - end |
419 | | - end |
420 | | -end |
421 | | - |
422 | | -@testset "Undirected Line Graph" begin |
423 | | - @testset "Undirected Cycle Graphs" begin |
424 | | - for n in 3:9 |
425 | | - g = cycle_graph(n) |
426 | | - lg = line_graph(g) # checking if lg is an n-cycle |
427 | | - @test nv(lg) == n |
428 | | - @test ne(lg) == n |
429 | | - @test is_connected(lg) |
430 | | - @test all(degree(lg, v) == 2 for v in vertices(lg)) |
431 | | - end |
432 | | - end |
433 | | - |
434 | | - @testset "Undirected Path Graphs" begin |
435 | | - for n in 2:9 |
436 | | - g = path_graph(n) |
437 | | - lg = line_graph(g) # checking if lg is an n-1-path |
438 | | - @test nv(lg) == n - 1 |
439 | | - @test ne(lg) == n - 2 |
440 | | - @test is_connected(lg) |
441 | | - @test all(degree(lg, v) <= 2 for v in vertices(lg)) |
442 | | - @test any(degree(lg, v) == 1 for v in vertices(lg)) || n == 2 && ne(lg) == 0 |
443 | 445 | end |
444 | 446 | end |
445 | | - |
446 | | - @testset "Undirected Star Graphs" begin |
447 | | - for n in 3:9 |
448 | | - g = star_graph(n) |
449 | | - lg = line_graph(g) # checking if lg is a complete graph on n-1 vertices |
450 | | - @test nv(lg) == n - 1 |
451 | | - @test ne(lg) == binomial(n - 1, 2) # lg must be a complete graph |
452 | | - end |
453 | | - end |
454 | | - |
455 | | - @testset "Undirected Self-loops" begin |
456 | | - g = SimpleGraph(2, [[2], [1, 2], Int[]]) |
457 | | - lg = line_graph(g) |
458 | | - @test nv(lg) == 2 # only 2 edges (self-loop counts once) |
459 | | - @test ne(lg) == 1 # only connection between edge 1-2 and self-loop 2-2 |
460 | | - end |
461 | | - |
462 | | - |
463 | 447 | end |
0 commit comments