|
1 | 1 | @testset "Betweenness" begin
|
2 | 2 | rng = StableRNG(1)
|
3 | 3 | # self loops
|
4 |
| - s2 = SimpleDiGraph(3) |
5 |
| - add_edge!(s2, 1, 2) |
6 |
| - add_edge!(s2, 2, 3) |
7 |
| - add_edge!(s2, 3, 3) |
8 |
| - s1 = SimpleGraph(s2) |
9 |
| - g3 = path_graph(5) |
| 4 | + s1 = GenericGraph(SimpleGraph(Edge.([(1,2), (2,3), (3, 3)]))) |
| 5 | + s2 = GenericDiGraph(SimpleDiGraph(Edge.([(1,2), (2,3), (3, 3)]))) |
| 6 | + |
| 7 | + g3 = GenericGraph(path_graph(5)) |
10 | 8 |
|
11 | 9 | gint = loadgraph(joinpath(testdir, "testdata", "graph-50-500.jgz"), "graph-50-500")
|
12 | 10 |
|
13 | 11 | c = vec(readdlm(joinpath(testdir, "testdata", "graph-50-500-bc.txt"), ','))
|
14 |
| - for g in testdigraphs(gint) |
| 12 | + for g in test_generic_graphs(gint) |
15 | 13 | z = @inferred(betweenness_centrality(g))
|
16 | 14 | @test map(Float32, z) == map(Float32, c)
|
17 | 15 |
|
|
29 | 27 | @test @inferred(betweenness_centrality(s1)) == [0, 1, 0]
|
30 | 28 | @test @inferred(betweenness_centrality(s2)) == [0, 0.5, 0]
|
31 | 29 |
|
32 |
| - g = SimpleGraph(2) |
33 |
| - add_edge!(g, 1, 2) |
| 30 | + g = GenericGraph(path_graph(2)) |
34 | 31 | z = @inferred(betweenness_centrality(g; normalize=true))
|
35 | 32 | @test z[1] == z[2] == 0.0
|
36 | 33 | z2 = @inferred(betweenness_centrality(g, vertices(g)))
|
37 |
| - z3 = @inferred(betweenness_centrality(g, [vertices(g);])) |
| 34 | + z3 = @inferred(betweenness_centrality(g, collect(vertices(g)))) |
38 | 35 | @test z == z2 == z3
|
39 | 36 |
|
40 | 37 | z = @inferred(betweenness_centrality(g3; normalize=false))
|
41 | 38 | @test z[1] == z[5] == 0.0
|
42 | 39 |
|
43 | 40 | # Weighted Graph tests
|
44 |
| - g = Graph(6) |
45 |
| - add_edge!(g, 1, 2) |
46 |
| - add_edge!(g, 2, 3) |
47 |
| - add_edge!(g, 3, 4) |
48 |
| - add_edge!(g, 2, 5) |
49 |
| - add_edge!(g, 5, 6) |
50 |
| - add_edge!(g, 5, 4) |
| 41 | + g = GenericGraph(SimpleGraph(Edge.([(1, 2), (2, 3), (2, 5), (3, 4), (4, 5), (5, 6)]))) |
51 | 42 |
|
52 | 43 | distmx = [
|
53 | 44 | 0.0 2.0 0.0 0.0 0.0 0.0
|
|
77 | 68 |
|
78 | 69 | adjmx2 = [0 1 0; 1 0 1; 1 1 0] # digraph
|
79 | 70 | a2 = SimpleDiGraph(adjmx2)
|
80 |
| - for g in testdigraphs(a2) |
| 71 | + for g in test_generic_graphs(a2) |
81 | 72 | distmx2 = [Inf 2.0 Inf; 3.2 Inf 4.2; 5.5 6.1 Inf]
|
82 | 73 | c2 = [0.24390243902439027, 0.27027027027027023, 0.1724137931034483]
|
83 | 74 | @test isapprox(
|
|
99 | 90 | )
|
100 | 91 | end
|
101 | 92 | # test #1405 / #1406
|
102 |
| - g = grid([50, 50]) |
| 93 | + g = GenericGraph(grid([50, 50])) |
103 | 94 | z = betweenness_centrality(g; normalize=false)
|
104 | 95 | @test maximum(z) < nv(g) * (nv(g) - 1)
|
105 | 96 | end
|
0 commit comments