|
1 | | -@testset "generate" begin |
2 | | - @testset "rand_graph" begin |
3 | | - n, m = 10, 20 |
4 | | - m2 = m ÷ 2 |
5 | | - x = rand(3, n) |
6 | | - e = rand(4, m2) |
| 1 | +@testset "rand_graph" begin |
| 2 | + n, m = 10, 20 |
| 3 | + m2 = m ÷ 2 |
| 4 | + x = rand(3, n) |
| 5 | + e = rand(4, m2) |
7 | 6 |
|
8 | | - g = rand_graph(n, m, ndata = x, edata = e, graph_type = GRAPH_T) |
9 | | - @test g.num_nodes == n |
10 | | - @test g.num_edges == m |
11 | | - @test g.ndata.x === x |
12 | | - if GRAPH_T == :coo |
13 | | - s, t = edge_index(g) |
14 | | - @test s[1:m2] == t[(m2 + 1):end] |
15 | | - @test t[1:m2] == s[(m2 + 1):end] |
16 | | - @test g.edata.e[:, 1:m2] == e |
17 | | - @test g.edata.e[:, (m2 + 1):end] == e |
18 | | - end |
| 7 | + g = rand_graph(n, m, ndata = x, edata = e, graph_type = GRAPH_T) |
| 8 | + @test g.num_nodes == n |
| 9 | + @test g.num_edges == m |
| 10 | + @test g.ndata.x === x |
| 11 | + if GRAPH_T == :coo |
| 12 | + s, t = edge_index(g) |
| 13 | + @test s[1:m2] == t[(m2 + 1):end] |
| 14 | + @test t[1:m2] == s[(m2 + 1):end] |
| 15 | + @test g.edata.e[:, 1:m2] == e |
| 16 | + @test g.edata.e[:, (m2 + 1):end] == e |
| 17 | + end |
19 | 18 |
|
20 | | - g = rand_graph(n, m, bidirected = false, seed = 17, graph_type = GRAPH_T) |
21 | | - @test g.num_nodes == n |
22 | | - @test g.num_edges == m |
| 19 | + g = rand_graph(n, m, bidirected = false, seed = 17, graph_type = GRAPH_T) |
| 20 | + @test g.num_nodes == n |
| 21 | + @test g.num_edges == m |
23 | 22 |
|
24 | | - g2 = rand_graph(n, m, bidirected = false, seed = 17, graph_type = GRAPH_T) |
25 | | - @test edge_index(g2) == edge_index(g) |
26 | | - end |
| 23 | + g2 = rand_graph(n, m, bidirected = false, seed = 17, graph_type = GRAPH_T) |
| 24 | + @test edge_index(g2) == edge_index(g) |
| 25 | +end |
27 | 26 |
|
28 | | - @testset "knn_graph" begin |
29 | | - n, k = 10, 3 |
30 | | - x = rand(3, n) |
31 | | - g = knn_graph(x, k; graph_type = GRAPH_T) |
32 | | - @test g.num_nodes == 10 |
33 | | - @test g.num_edges == n * k |
34 | | - @test degree(g, dir = :in) == fill(k, n) |
35 | | - @test has_self_loops(g) == false |
| 27 | +@testset "knn_graph" begin |
| 28 | + n, k = 10, 3 |
| 29 | + x = rand(3, n) |
| 30 | + g = knn_graph(x, k; graph_type = GRAPH_T) |
| 31 | + @test g.num_nodes == 10 |
| 32 | + @test g.num_edges == n * k |
| 33 | + @test degree(g, dir = :in) == fill(k, n) |
| 34 | + @test has_self_loops(g) == false |
36 | 35 |
|
37 | | - g = knn_graph(x, k; dir = :out, self_loops = true, graph_type = GRAPH_T) |
38 | | - @test g.num_nodes == 10 |
39 | | - @test g.num_edges == n * k |
40 | | - @test degree(g, dir = :out) == fill(k, n) |
41 | | - @test has_self_loops(g) == true |
| 36 | + g = knn_graph(x, k; dir = :out, self_loops = true, graph_type = GRAPH_T) |
| 37 | + @test g.num_nodes == 10 |
| 38 | + @test g.num_edges == n * k |
| 39 | + @test degree(g, dir = :out) == fill(k, n) |
| 40 | + @test has_self_loops(g) == true |
42 | 41 |
|
43 | | - graph_indicator = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2] |
44 | | - g = knn_graph(x, k; graph_indicator, graph_type = GRAPH_T) |
45 | | - @test g.num_graphs == 2 |
46 | | - s, t = edge_index(g) |
47 | | - ne = n * k ÷ 2 |
48 | | - @test all(1 .<= s[1:ne] .<= 5) |
49 | | - @test all(1 .<= t[1:ne] .<= 5) |
50 | | - @test all(6 .<= s[(ne + 1):end] .<= 10) |
51 | | - @test all(6 .<= t[(ne + 1):end] .<= 10) |
52 | | - end |
| 42 | + graph_indicator = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2] |
| 43 | + g = knn_graph(x, k; graph_indicator, graph_type = GRAPH_T) |
| 44 | + @test g.num_graphs == 2 |
| 45 | + s, t = edge_index(g) |
| 46 | + ne = n * k ÷ 2 |
| 47 | + @test all(1 .<= s[1:ne] .<= 5) |
| 48 | + @test all(1 .<= t[1:ne] .<= 5) |
| 49 | + @test all(6 .<= s[(ne + 1):end] .<= 10) |
| 50 | + @test all(6 .<= t[(ne + 1):end] .<= 10) |
| 51 | +end |
53 | 52 |
|
54 | | - @testset "radius_graph" begin |
55 | | - n, r = 10, 0.5 |
56 | | - x = rand(3, n) |
57 | | - g = radius_graph(x, r; graph_type = GRAPH_T) |
58 | | - @test g.num_nodes == 10 |
59 | | - @test has_self_loops(g) == false |
| 53 | +@testset "radius_graph" begin |
| 54 | + n, r = 10, 0.5 |
| 55 | + x = rand(3, n) |
| 56 | + g = radius_graph(x, r; graph_type = GRAPH_T) |
| 57 | + @test g.num_nodes == 10 |
| 58 | + @test has_self_loops(g) == false |
60 | 59 |
|
61 | | - g = radius_graph(x, r; dir = :out, self_loops = true, graph_type = GRAPH_T) |
62 | | - @test g.num_nodes == 10 |
63 | | - @test has_self_loops(g) == true |
| 60 | + g = radius_graph(x, r; dir = :out, self_loops = true, graph_type = GRAPH_T) |
| 61 | + @test g.num_nodes == 10 |
| 62 | + @test has_self_loops(g) == true |
64 | 63 |
|
65 | | - graph_indicator = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2] |
66 | | - g = radius_graph(x, r; graph_indicator, graph_type = GRAPH_T) |
67 | | - @test g.num_graphs == 2 |
68 | | - s, t = edge_index(g) |
69 | | - @test (s .> 5) == (t .> 5) |
70 | | - end |
| 64 | + graph_indicator = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2] |
| 65 | + g = radius_graph(x, r; graph_indicator, graph_type = GRAPH_T) |
| 66 | + @test g.num_graphs == 2 |
| 67 | + s, t = edge_index(g) |
| 68 | + @test (s .> 5) == (t .> 5) |
71 | 69 | end |
0 commit comments