|
1 | 1 | using LinearAlgebra |
2 | 2 | using SparseArrays |
3 | | -using SparseMatrixColorings: Graph, adjacency_graph, bipartite_graph, neighbors |
| 3 | +using SparseMatrixColorings: Graph, adjacency_graph, bipartite_graph, degree, neighbors |
4 | 4 | using Test |
5 | 5 |
|
6 | 6 | ## Standard graph |
7 | 7 |
|
8 | 8 | @testset "Graph" begin |
9 | | - g = Graph(sparse([ |
| 9 | + g = Graph{true}(sparse([ |
10 | 10 | 1 0 1 |
11 | 11 | 1 1 0 |
12 | 12 | 0 0 0 |
13 | 13 | ])) |
14 | 14 |
|
15 | 15 | @test length(g) == 3 |
| 16 | + @test nnz(g) == 4 |
16 | 17 | @test neighbors(g, 1) == [1, 2] |
17 | 18 | @test neighbors(g, 2) == [2] |
18 | 19 | @test neighbors(g, 3) == [1] |
| 20 | + @test degree(g, 1) == 2 |
| 21 | + @test degree(g, 2) == 1 |
| 22 | + @test degree(g, 3) == 1 |
| 23 | + |
| 24 | + g = Graph{false}(sparse([ |
| 25 | + 1 0 1 |
| 26 | + 1 1 0 |
| 27 | + 0 0 0 |
| 28 | + ])) |
| 29 | + |
| 30 | + @test length(g) == 3 |
| 31 | + @test nnz(g) == 2 |
| 32 | + @test collect(neighbors(g, 1)) == [2] |
| 33 | + @test collect(neighbors(g, 2)) == Int[] |
| 34 | + @test collect(neighbors(g, 3)) == [1] |
| 35 | + @test degree(g, 1) == 1 |
| 36 | + @test degree(g, 2) == 0 |
| 37 | + @test degree(g, 3) == 1 |
19 | 38 | end; |
20 | 39 |
|
21 | 40 | ## Bipartite graph (fig 3.1 of "What color is your Jacobian?") |
|
76 | 95 | B = transpose(A) * A |
77 | 96 | g = adjacency_graph(B - Diagonal(B)) |
78 | 97 | @test length(g) == 8 |
79 | | - @test neighbors(g, 1) == [6, 7, 8] |
80 | | - @test neighbors(g, 2) == [5, 7, 8] |
81 | | - @test neighbors(g, 3) == [5, 6, 8] |
82 | | - @test neighbors(g, 4) == [5, 6, 7] |
83 | | - @test neighbors(g, 5) == [2, 3, 4, 6, 7, 8] |
84 | | - @test neighbors(g, 6) == [1, 3, 4, 5, 7, 8] |
85 | | - @test neighbors(g, 7) == [1, 2, 4, 5, 6, 8] |
86 | | - @test neighbors(g, 8) == [1, 2, 3, 5, 6, 7] |
| 98 | + @test collect(neighbors(g, 1)) == [6, 7, 8] |
| 99 | + @test collect(neighbors(g, 2)) == [5, 7, 8] |
| 100 | + @test collect(neighbors(g, 3)) == [5, 6, 8] |
| 101 | + @test collect(neighbors(g, 4)) == [5, 6, 7] |
| 102 | + @test collect(neighbors(g, 5)) == [2, 3, 4, 6, 7, 8] |
| 103 | + @test collect(neighbors(g, 6)) == [1, 3, 4, 5, 7, 8] |
| 104 | + @test collect(neighbors(g, 7)) == [1, 2, 4, 5, 6, 8] |
| 105 | + @test collect(neighbors(g, 8)) == [1, 2, 3, 5, 6, 7] |
87 | 106 | end |
0 commit comments