|
7 | 7 | add_edge!(gx, 8, 9) |
8 | 8 | add_edge!(gx, 10, 9) |
9 | 9 |
|
10 | | - for g in testgraphs(gx) |
| 10 | + for g in test_generic_graphs(gx) |
11 | 11 | @test @inferred(!is_connected(g)) |
12 | 12 | cc = @inferred(connected_components(g)) |
13 | 13 | label = zeros(eltype(g), nv(g)) |
|
20 | 20 | @test cclab[8] == [8, 9, 10] |
21 | 21 | @test length(cc) >= 3 && sort(cc[3]) == [8, 9, 10] |
22 | 22 | end |
23 | | - for g in testgraphs(g6) |
| 23 | + for g in test_generic_graphs(g6) |
24 | 24 | @test @inferred(is_connected(g)) |
25 | 25 | end |
26 | 26 |
|
27 | 27 | g10 = SimpleDiGraph(4) |
28 | 28 | add_edge!(g10, 1, 3) |
29 | 29 | add_edge!(g10, 2, 4) |
30 | | - for g in testdigraphs(g10) |
| 30 | + for g in test_generic_graphs(g10) |
31 | 31 | @test @inferred(is_bipartite(g)) |
32 | 32 | end |
33 | 33 | add_edge!(g10, 1, 4) |
34 | | - for g in testdigraphs(g10) |
| 34 | + for g in test_generic_graphs(g10) |
35 | 35 | @test @inferred(is_bipartite(g)) |
36 | 36 | end |
37 | 37 |
|
|
45 | 45 | end |
46 | 46 | if !has_edge(g, i, j) |
47 | 47 | add_edge!(g, i, j) |
48 | | - @test @inferred(is_bipartite(g)) |
| 48 | + @test @inferred(is_bipartite(GenericDiGraph(g))) |
49 | 49 | end |
50 | 50 | end |
51 | 51 | end |
|
66 | 66 | add_edge!(h, 7, 6) |
67 | 67 | add_edge!(h, 8, 4) |
68 | 68 | add_edge!(h, 8, 7) |
69 | | - for g in testdigraphs(h) |
| 69 | + for g in test_generic_graphs(h) |
70 | 70 | @test @inferred(is_weakly_connected(g)) |
71 | 71 | scc = @inferred(strongly_connected_components(g)) |
72 | 72 | scc_k = @inferred(strongly_connected_components_kosaraju(g)) |
|
77 | 77 | @test length(wcc) == 1 && length(wcc[1]) == nv(g) |
78 | 78 | end |
79 | 79 |
|
80 | | - function scc_ok(graph) |
| 80 | + function scc_ok(graph::GenericDiGraph) |
81 | 81 | # Check that all SCC really are strongly connected |
| 82 | + |
| 83 | + # TODO it might be better if we did not have to unwrap the GenericDiGraph |
| 84 | + # (and we somehow might prevent this in the future) but currently the methods |
| 85 | + # used in this utility test function do not work with GenericDiGraph yet. |
| 86 | + graph = graph.g |
| 87 | + |
82 | 88 | scc = @inferred(strongly_connected_components(graph)) |
83 | 89 | scc_as_subgraphs = map(i -> graph[i], scc) |
84 | 90 | return all(is_strongly_connected, scc_as_subgraphs) |
85 | 91 | end |
86 | 92 |
|
87 | | - function scc_k_ok(graph) |
| 93 | + function scc_k_ok(graph::GenericDiGraph) |
88 | 94 | # Check that all SCC really are strongly connected |
| 95 | + |
| 96 | + # TODO it might be better if we did not have to unwrap the GenericDiGraph |
| 97 | + # (and we somehow might prevent this in the future) but currently the methods |
| 98 | + # used in this utility test function do not work with GenericDiGraph yet. |
| 99 | + graph = graph.g |
| 100 | + |
89 | 101 | scc_k = @inferred(strongly_connected_components_kosaraju(graph)) |
90 | 102 | scc_k_as_subgraphs = map(i -> graph[i], scc_k) |
91 | 103 | return all(is_strongly_connected, scc_k_as_subgraphs) |
|
97 | 109 | add_edge!(h, 4, 2) |
98 | 110 | add_edge!(h, 2, 3) |
99 | 111 | add_edge!(h, 1, 3) |
100 | | - for g in testdigraphs(h) |
| 112 | + for g in test_generic_graphs(h) |
101 | 113 | @test scc_ok(g) |
102 | 114 | @test scc_k_ok(g) |
103 | 115 | end |
|
107 | 119 | add_edge!(h2, 2, 4) |
108 | 120 | add_edge!(h2, 4, 3) |
109 | 121 | add_edge!(h2, 1, 3) |
110 | | - for g in testdigraphs(h2) |
| 122 | + for g in test_generic_graphs(h2) |
111 | 123 | @test scc_ok(g) |
112 | 124 | @test scc_k_ok(g) |
113 | 125 | end |
114 | 126 |
|
115 | 127 | # Test case for empty graph |
116 | 128 | h = SimpleDiGraph(0) |
117 | | - for g in testdigraphs(h) |
| 129 | + for g in test_generic_graphs(h) |
118 | 130 | scc = @inferred(strongly_connected_components(g)) |
119 | 131 | scc_k = @inferred(strongly_connected_components_kosaraju(g)) |
120 | 132 | @test length(scc) == 0 |
|
123 | 135 |
|
124 | 136 | # Test case for graph with one vertex |
125 | 137 | h = SimpleDiGraph(1) |
126 | | - for g in testdigraphs(h) |
| 138 | + for g in test_generic_graphs(h) |
127 | 139 | scc = @inferred(strongly_connected_components(g)) |
128 | 140 | scc_k = @inferred(strongly_connected_components_kosaraju(g)) |
129 | 141 | @test length(scc) == 1 && scc[1] == [1] |
|
139 | 151 | add_edge!(h, 2, 3) |
140 | 152 | add_edge!(h, 2, 1) |
141 | 153 |
|
142 | | - for g in testdigraphs(h) |
| 154 | + for g in test_generic_graphs(h) |
143 | 155 | scc = @inferred(strongly_connected_components(g)) |
144 | 156 | scc_k = @inferred(strongly_connected_components_kosaraju(g)) |
145 | 157 | @test length(scc) == 2 |
|
159 | 171 | add_edge!(h, 3, 5) |
160 | 172 | add_edge!(h, 5, 6) |
161 | 173 | add_edge!(h, 6, 4) |
162 | | - for g in testdigraphs(h) |
| 174 | + for g in test_generic_graphs(h) |
163 | 175 | scc = @inferred(strongly_connected_components(g)) |
164 | 176 | scc_k = @inferred(strongly_connected_components_kosaraju(g)) |
165 | 177 | @test length(scc) == 1 && sort(scc[1]) == [1:6;] |
|
171 | 183 | add_edge!(h, 2, 3) |
172 | 184 | add_edge!(h, 3, 1) |
173 | 185 | add_edge!(h, 4, 1) |
174 | | - for g in testdigraphs(h) |
| 186 | + for g in test_generic_graphs(h) |
175 | 187 | scc = @inferred(strongly_connected_components(g)) |
176 | 188 | scc_k = @inferred(strongly_connected_components_kosaraju(g)) |
177 | 189 | @test length(scc) == 2 && sort(scc[1]) == [1:3;] && sort(scc[2]) == [4] |
|
200 | 212 | add_edge!(h, 11, 12) |
201 | 213 | add_edge!(h, 12, 10) |
202 | 214 |
|
203 | | - for g in testdigraphs(h) |
| 215 | + for g in test_generic_graphs(h) |
204 | 216 | scc = @inferred(strongly_connected_components(g)) |
205 | 217 | scc_k = @inferred(strongly_connected_components_kosaraju(g)) |
206 | 218 | @test length(scc) == 4 |
|
224 | 236 | fig1[[3, 4, 9, 10, 11, 13, 18, 19, 22, 24]] = [ |
225 | 237 | 0.5, 0.4, 0.1, 1.0, 1.0, 0.2, 0.3, 0.2, 1.0, 0.3 |
226 | 238 | ] |
227 | | - fig1 = SimpleDiGraph(fig1) |
| 239 | + fig1 = GenericDiGraph(SimpleDiGraph(fig1)) |
228 | 240 | scc_fig1 = Vector[[2, 5], [1, 3, 4]] |
229 | 241 |
|
230 | 242 | # figure 2 example |
231 | 243 | fig2 = spzeros(5, 5) |
232 | 244 | fig2[[3, 10, 11, 13, 14, 17, 18, 19, 22]] .= 1 |
233 | | - fig2 = SimpleDiGraph(fig2) |
| 245 | + fig2 = GenericDiGraph(SimpleDiGraph(fig2)) |
234 | 246 |
|
235 | 247 | # figure 3 example |
236 | 248 | fig3 = spzeros(8, 8) |
237 | 249 | fig3[[ |
238 | 250 | 1, 7, 9, 13, 14, 15, 18, 20, 23, 27, 28, 31, 33, 34, 37, 45, 46, 49, 57, 63, 64 |
239 | 251 | ]] .= 1 |
240 | | - fig3 = SimpleDiGraph(fig3) |
| 252 | + fig3 = GenericDiGraph(SimpleDiGraph(fig3)) |
241 | 253 | scc_fig3 = Vector[[3, 4], [2, 5, 6], [8], [1, 7]] |
242 | 254 | fig3_cond = SimpleDiGraph(4) |
243 | 255 | add_edge!(fig3_cond, 4, 3) |
244 | 256 | add_edge!(fig3_cond, 2, 1) |
245 | 257 | add_edge!(fig3_cond, 4, 1) |
246 | 258 | add_edge!(fig3_cond, 4, 2) |
| 259 | + fig3_cond |
247 | 260 |
|
248 | 261 | # construct a n-number edge ring graph (period = n) |
249 | 262 | n = 10 |
250 | 263 | n_ring = cycle_digraph(n) |
251 | 264 | n_ring_shortcut = copy(n_ring) |
252 | 265 | add_edge!(n_ring_shortcut, 1, 4) |
| 266 | + n_ring = GenericDiGraph(n_ring) |
| 267 | + n_ring_shortcut = GenericDiGraph(n_ring_shortcut) |
253 | 268 |
|
254 | 269 | # figure 8 example |
255 | 270 | fig8 = spzeros(6, 6) |
256 | 271 | fig8[[2, 10, 13, 21, 24, 27, 35]] .= 1 |
257 | | - fig8 = SimpleDiGraph(fig8) |
| 272 | + fig8 = GenericDiGraph(SimpleDiGraph(fig8)) |
258 | 273 |
|
259 | 274 | @test Set(@inferred(strongly_connected_components(fig1))) == Set(scc_fig1) |
260 | 275 | @test Set(@inferred(strongly_connected_components(fig3))) == Set(scc_fig3) |
261 | 276 |
|
262 | 277 | @test @inferred(period(n_ring)) == n |
263 | 278 | @test @inferred(period(n_ring_shortcut)) == 2 |
264 | 279 |
|
| 280 | + # TODO condensation currently returns a SimpleDiGraph, even if the input graph |
| 281 | + # is a GenericDiGraph, so we compare with a SimpleDiGraph in this test, |
| 282 | + # but one should think, if the condensation should not also be a GenericDiGraph |
265 | 283 | @test @inferred(condensation(fig3)) == fig3_cond |
266 | 284 |
|
267 | 285 | @test @inferred(attracting_components(fig1)) == Vector[[2, 5]] |
|
270 | 288 | g10dists = ones(10, 10) |
271 | 289 | g10dists[1, 2] = 10.0 |
272 | 290 | g10 = star_graph(10) |
273 | | - for g in testgraphs(g10) |
| 291 | + for g in test_generic_graphs(g10) |
274 | 292 | @test @inferred(neighborhood_dists(g, 1, 0)) == [(1, 0)] |
275 | 293 | @test length(@inferred(neighborhood(g, 1, 1))) == 10 |
276 | 294 | @test length(@inferred(neighborhood(g, 1, 1, g10dists))) == 9 |
|
280 | 298 | @test length(@inferred(neighborhood(g, 2, -1))) == 0 |
281 | 299 | end |
282 | 300 | g10 = star_digraph(10) |
283 | | - for g in testdigraphs(g10) |
284 | | - @test @inferred(neighborhood_dists(g10, 1, 0, dir=:out)) == [(1, 0)] |
| 301 | + for g in test_generic_graphs(g10) |
| 302 | + @test @inferred(neighborhood_dists(g, 1, 0, dir=:out)) == [(1, 0)] |
285 | 303 | @test length(@inferred(neighborhood(g, 1, 1, dir=:out))) == 10 |
286 | 304 | @test length(@inferred(neighborhood(g, 1, 1, g10dists, dir=:out))) == 9 |
287 | 305 | @test length(@inferred(neighborhood(g, 2, 1, dir=:out))) == 1 |
|
301 | 319 | ##@test !@inferred(isgraphical([2])) |
302 | 320 |
|
303 | 321 | # Test simple digraphicality |
304 | | - sdg = SimpleDiGraph(10, 90) |
| 322 | + sdg = GenericDiGraph(SimpleDiGraph(10, 90)) |
305 | 323 | @test @inferred(isdigraphical(indegree(sdg), outdegree(sdg))) |
306 | 324 | @test !@inferred(isdigraphical([1, 1, 1], [1, 1, 0])) |
307 | 325 | @test @inferred(isdigraphical(Integer[], Integer[])) |
|
314 | 332 |
|
315 | 333 | # 1116 |
316 | 334 | gc = cycle_graph(4) |
317 | | - for g in testgraphs(gc) |
| 335 | + for g in test_generic_graphs(gc) |
318 | 336 | z = @inferred(neighborhood(g, 3, 3)) |
319 | 337 | @test (z == [3, 2, 4, 1] || z == [3, 4, 2, 1]) |
320 | 338 | end |
321 | 339 |
|
322 | 340 | gd = SimpleDiGraph([0 1 1 0; 0 0 0 1; 0 0 0 1; 0 0 0 0]) |
323 | 341 | add_edge!(gd, 1, 4) |
324 | | - for g in testdigraphs(gd) |
| 342 | + for g in test_generic_graphs(gd) |
325 | 343 | z = @inferred(neighborhood_dists(g, 1, 4)) |
326 | 344 | @test (4, 1) ∈ z |
327 | 345 | @test (4, 2) ∉ z |
|
0 commit comments