|
24 | 24 | @test isapprox(Q2, 0.6071428571428571, atol=1e-3) |
25 | 25 | end |
26 | 26 |
|
| 27 | + # Test with self loop |
| 28 | + add_edge!(barbell, 1, 1) |
| 29 | + for g in test_generic_graphs(barbell) |
| 30 | + Q = @inferred(modularity(g, c)) |
| 31 | + @test isapprox(Q, 0.3671875, atol=1e-3) |
| 32 | + end |
| 33 | + |
27 | 34 | # 2. directed test cases |
28 | 35 | triangle = SimpleDiGraph(3) |
29 | 36 | add_edge!(triangle, 1, 2) |
|
65 | 72 | Q = @inferred(modularity(g, c, distmx=d)) |
66 | 73 | @test isapprox(Q, 0.045454545454545456, atol=1e-3) |
67 | 74 | end |
| 75 | + # Add self loop with weight 5 |
| 76 | + add_edge!(barbell, 1, 1) |
| 77 | + d = [ |
| 78 | + [5 1 1 0 0 0] |
| 79 | + [1 0 1 0 0 0] |
| 80 | + [1 1 0 1 0 0] |
| 81 | + [0 0 1 0 1 1] |
| 82 | + [0 0 0 1 0 1] |
| 83 | + [0 0 0 1 1 0] |
| 84 | + ] |
| 85 | + for g in test_generic_graphs(barbell) |
| 86 | + Q = @inferred(modularity(g, c, distmx=d)) |
| 87 | + @test isapprox(Q, 0.329861, atol=1e-3) |
| 88 | + end |
68 | 89 |
|
69 | 90 | # 3.2. directed and weighted test cases |
70 | 91 | triangle = SimpleDiGraph(3) |
|
73 | 94 | add_edge!(triangle, 3, 1) |
74 | 95 |
|
75 | 96 | barbell = blockdiag(triangle, triangle) |
76 | | - add_edge!(barbell, 1, 4) # this edge has a weight of 5 |
| 97 | + add_edge!(barbell, 3, 4) # this edge has a weight of 5 |
77 | 98 | c = [1, 1, 1, 2, 2, 2] |
78 | 99 | d = [ |
79 | | - [0 1 0 5 0 0] |
| 100 | + [0 1 0 0 0 0] |
80 | 101 | [0 0 1 0 0 0] |
81 | | - [1 0 0 0 0 0] |
| 102 | + [1 0 0 5 0 0] |
82 | 103 | [0 0 0 0 1 0] |
83 | 104 | [0 0 0 0 0 1] |
84 | 105 | [0 0 0 1 0 0] |
|
87 | 108 | Q = @inferred(modularity(g, c, distmx=d)) |
88 | 109 | @test isapprox(Q, 0.1487603305785124, atol=1e-3) |
89 | 110 | end |
| 111 | + # Add self loop with weight 5 |
| 112 | + add_edge!(barbell, 1, 1) |
| 113 | + d = [ |
| 114 | + [5 1 0 0 0 0] |
| 115 | + [0 0 1 0 0 0] |
| 116 | + [1 0 0 1 0 0] |
| 117 | + [0 0 0 0 1 0] |
| 118 | + [0 0 0 0 0 1] |
| 119 | + [0 0 0 1 0 0] |
| 120 | + ] |
| 121 | + for g in test_generic_graphs(barbell) |
| 122 | + Q = @inferred(modularity(g, c, distmx=d)) |
| 123 | + @test isapprox(Q, 0.333333333, atol=1e-3) |
| 124 | + end |
90 | 125 | end |
0 commit comments