|
8 | 8 | 6 10 3 0 |
9 | 9 | ] |
10 | 10 |
|
| 11 | + weight_vector = [distmx[src(e), dst(e)] for e in edges(g4)] |
| 12 | + |
11 | 13 | vec_mst = Vector{Edge}([Edge(1, 2), Edge(3, 4), Edge(2, 3)]) |
12 | 14 | max_vec_mst = Vector{Edge}([Edge(2, 4), Edge(1, 4), Edge(1, 3)]) |
13 | 15 | for g in test_generic_graphs(g4) |
|
18 | 20 | # so instead we compare tuples of source and target vertices |
19 | 21 | @test sort([(src(e), dst(e)) for e in mst]) == sort([(src(e), dst(e)) for e in vec_mst]) |
20 | 22 | @test sort([(src(e), dst(e)) for e in max_mst]) == sort([(src(e), dst(e)) for e in max_vec_mst]) |
| 23 | + # test equivalent vector form |
| 24 | + mst_vec = @inferred(kruskal_mst(g, weight_vector)) |
| 25 | + max_mst_vec = @inferred(kruskal_mst(g, weight_vector, minimize=false)) |
| 26 | + @test src.(mst_vec) == src.(mst) |
| 27 | + @test dst.(mst_vec) == dst.(mst) |
| 28 | + @test src.(max_mst_vec) == src.(max_mst) |
| 29 | + @test dst.(max_mst_vec) == dst.(max_mst) |
21 | 30 | end |
| 31 | + |
22 | 32 | # second test |
23 | 33 | distmx_sec = [ |
24 | 34 | 0 0 0.26 0 0.38 0 0.58 0.16 |
|
32 | 42 | ] |
33 | 43 |
|
34 | 44 | gx = SimpleGraph(distmx_sec) |
| 45 | + weight_vector_sec = [distmx_sec[src(e), dst(e)] for e in edges(gx)] |
| 46 | + |
35 | 47 | vec2 = Vector{Edge}([ |
36 | 48 | Edge(1, 8), Edge(3, 4), Edge(2, 8), Edge(1, 3), Edge(6, 8), Edge(5, 6), Edge(3, 7) |
37 | 49 | ]) |
|
40 | 52 | ]) |
41 | 53 | for g in test_generic_graphs(gx) |
42 | 54 | mst2 = @inferred(kruskal_mst(g, distmx_sec)) |
| 55 | + mst2_vec = @inferred(kruskal_mst(g, weight_vector_sec)) |
43 | 56 | max_mst2 = @inferred(kruskal_mst(g, distmx_sec, minimize=false)) |
| 57 | + max_mst2_vec = @inferred(kruskal_mst(g, weight_vector_sec, minimize=false)) |
44 | 58 | @test sort([(src(e), dst(e)) for e in mst2]) == sort([(src(e), dst(e)) for e in vec2]) |
45 | 59 | @test sort([(src(e), dst(e)) for e in max_mst2]) == sort([(src(e), dst(e)) for e in max_vec2]) |
| 60 | + @test src.(mst2) == src.(mst2_vec) |
| 61 | + @test dst.(mst2) == dst.(mst2_vec) |
| 62 | + @test src.(max_mst2) == src.(max_mst2_vec) |
| 63 | + @test dst.(max_mst2) == dst.(max_mst2_vec) |
46 | 64 | end |
47 | 65 |
|
48 | 66 | # non regression test for #362 |
|
0 commit comments