@@ -6,51 +6,68 @@ using DistributedFactorGraphs.GraphsJlAPI
6
6
dfg = GraphsDFG ()
7
7
v1 = DFGVariable (:a )
8
8
v2 = DFGVariable (:b )
9
- addVariable! (dfg, v1)
10
- @test_throws Exception addVariable! (dfg, v1)
11
- addVariable! (dfg, v2)
12
9
f1 = DFGFactor (:f1 )
13
- addFactor! (dfg, f1, [v1, v2])
14
- @test_throws Exception addFactor! (dfg, DFGFactor (" f2" ), [v1, DFGVariable (" Nope" )])
10
+ @testset " Creating Graphs" begin
11
+ global dfg,v1,v2,f1
12
+ addVariable! (dfg, v1)
13
+ @test_throws Exception addVariable! (dfg, v1)
14
+ addVariable! (dfg, v2)
15
+ addFactor! (dfg, f1, [v1, v2])
16
+ @test_throws Exception addFactor! (dfg, DFGFactor (" f2" ), [v1, DFGVariable (" Nope" )])
17
+ end
15
18
16
- @test length (ls (dfg)) == 2
17
- @test length (lsf (dfg)) == 1
18
- # Regexes
19
- @test ls (dfg, r" a" ) == [v1]
20
- @test lsf (dfg, r" f*" ) == [f1]
19
+ @testset " Listing Nodes" begin
20
+ global dfg,v1,v2,f1
21
+ @test length (ls (dfg)) == 2
22
+ @test length (lsf (dfg)) == 1
23
+ # Regexes
24
+ @test ls (dfg, r" a" ) == [v1]
25
+ @test lsf (dfg, r" f*" ) == [f1]
26
+ end
21
27
22
28
# Gets
23
- @test getVariable (dfg, v1. label) == v1
24
- @test getFactor (dfg, f1. label) == f1
25
- @test_throws Exception getVariable (dfg, :nope )
26
- @test_throws Exception getVariable (dfg, " nope" )
27
- @test_throws Exception getFactor (dfg, :nope )
28
- @test_throws Exception getFactor (dfg, " nope" )
29
+ @testset " Gets and Sets" begin
30
+ global dfg,v1,v2,f1
31
+ @test getVariable (dfg, v1. label) == v1
32
+ @test getFactor (dfg, f1. label) == f1
33
+ @test_throws Exception getVariable (dfg, :nope )
34
+ @test_throws Exception getVariable (dfg, " nope" )
35
+ @test_throws Exception getFactor (dfg, :nope )
36
+ @test_throws Exception getFactor (dfg, " nope" )
29
37
30
- # Sets
31
- v1Prime = deepcopy (v1)
32
- @test updateVariable (dfg, v1Prime) != v1
33
- f1Prime = deepcopy (f1)
34
- @test updateFactor (dfg, f1Prime) != f1
38
+ # Sets
39
+ v1Prime = deepcopy (v1)
40
+ @test updateVariable (dfg, v1Prime) != v1
41
+ f1Prime = deepcopy (f1)
42
+ @test updateFactor (dfg, f1Prime) != f1
43
+ end
35
44
36
45
# Deletions
37
46
# Not supported at present
38
- @warn " Deletions with Graph.jl is not supported at present"
47
+ @testset " Deletions" begin
48
+ @warn " Deletions with Graph.jl is not supported at present"
49
+ end
39
50
40
51
# Connectivity test
41
- @test isFullyConnected (dfg) == true
42
- addVariable! (dfg, DFGVariable (:orphan ))
43
- @test isFullyConnected (dfg) == false
52
+ @testset " Connectivity Test" begin
53
+ global dfg,v1,v2,f1
54
+ @test isFullyConnected (dfg) == true
55
+ addVariable! (dfg, DFGVariable (:orphan ))
56
+ @test isFullyConnected (dfg) == false
57
+ end
44
58
45
59
# Adjacency matrices
46
- adjMat = getAdjacencyMatrixDataFrame (dfg)
47
- @test size (adjMat) == (4 ,4 )
48
-
49
- # Testing
50
- using Test
51
- using DataFrames
52
- using DistributedFactorGraphs
53
- using DistributedFactorGraphs. GraphsJlAPI
60
+ @testset " Adjacency Matrices" begin
61
+ global dfg,v1,v2,f1
62
+ # Normal
63
+ adjMat = getAdjacencyMatrix (dfg)
64
+ @test size (adjMat) == (2 ,4 )
65
+ @test adjMat[1 , :] == [nothing , :a , :b , :orphan ]
66
+ @test adjMat[2 , :] == [:f1 , :f1 , :f1 , nothing ]
67
+ # Dataframe
68
+ adjDf = getAdjacencyMatrixDataFrame (dfg)
69
+ @test size (adjDf) == (1 ,4 )
70
+ end
54
71
55
72
# Now make a complex graph for connectivity tests
56
73
numNodes = 10
@@ -59,37 +76,27 @@ verts = map(n -> DFGVariable(Symbol("x$n")), 1:numNodes)
59
76
map (v -> addVariable! (dfg, v), verts)
60
77
map (n -> addFactor! (dfg, DFGFactor (Symbol (" x$(n) x$(n+ 1 ) f1" )), [verts[n], verts[n+ 1 ]]), 1 : (numNodes- 1 ))
61
78
# map(n -> addFactor!(dfg, [verts[n], verts[n+2]], DFGFactor(Symbol("x$(n)x$(n+2)f2"))), 1:2:(numNodes-2))
62
- adjMat = getAdjacencyMatrixDataFrame (dfg)
63
79
64
- # Get neighbors tests
65
- @test getNeighbors (dfg, verts[1 ]) == [:x1x2f1 ]
66
- neighbors = getNeighbors (dfg, getFactor (dfg, :x1x2f1 ))
67
- @test all ([v in [:x1 , :x2 ] for v in neighbors])
68
- # Testing aliases
69
- @test getNeighbors (dfg, getFactor (dfg, :x1x2f1 )) == ls (dfg, getFactor (dfg, :x1x2f1 ))
70
- @test getNeighbors (dfg, :x1x2f1 ) == ls (dfg, :x1x2f1 )
71
-
72
- # Subgraphs
73
- dfgSubgraph = getSubgraphAroundNode (dfg, verts[1 ], 2 )
74
- # Only returns x1 and x2
75
- @test all ([v in [:x1 , :x1x2f1 , :x2 ] for v in map (n -> n. label, [ls (dfgSubgraph)... , lsf (dfgSubgraph)... ])])
76
- # Test include orphan factorsVoid
77
- dfgSubgraph = getSubgraphAroundNode (dfg, verts[1 ], 1 , true )
78
- @test all ([v in [:x1 , :x1x2f1 ] for v in map (n -> n. label, [ls (dfgSubgraph)... , lsf (dfgSubgraph)... ])])
79
- # Test adding to the dfg
80
- dfgSubgraph = getSubgraphAroundNode (dfg, verts[1 ], 2 , true , dfgSubgraph)
81
- @test all ([v in [:x1 , :x1x2f1 , :x2 ] for v in map (n -> n. label, [ls (dfgSubgraph)... , lsf (dfgSubgraph)... ])])
82
-
83
- # Adjacency matrix
84
- varLabels = sort (map (v-> v. label, getVariables (dfg)))
85
- factLabels = sort (map (f-> f. label, getFactors (dfg)))
86
- adjDf = DataFrame (:Factor => Union{Missing, Symbol}[])
87
- for varLabel in varLabels
88
- adjDf[varLabel] = Union{Missing, Symbol}[]
80
+ @testset " Getting Neighbors" begin
81
+ global dfg,verts
82
+ # Get neighbors tests
83
+ @test getNeighbors (dfg, verts[1 ]) == [:x1x2f1 ]
84
+ neighbors = getNeighbors (dfg, getFactor (dfg, :x1x2f1 ))
85
+ @test all ([v in [:x1 , :x2 ] for v in neighbors])
86
+ # Testing aliases
87
+ @test getNeighbors (dfg, getFactor (dfg, :x1x2f1 )) == ls (dfg, getFactor (dfg, :x1x2f1 ))
88
+ @test getNeighbors (dfg, :x1x2f1 ) == ls (dfg, :x1x2f1 )
89
89
end
90
- for (i, factLabel) in enumerate (factLabels)
91
- global adjDf
92
- push! (adjDf, [factLabel, missings (length (varLabels))... ])
93
- factVars = getNeighbors (dfg, getFactor (dfg, factLabel))
94
- map (vLabel -> adjDf[vLabel][i] = factLabel, factVars)
90
+
91
+ @testset " Getting Subgraphs" begin
92
+ # Subgraphs
93
+ dfgSubgraph = getSubgraphAroundNode (dfg, verts[1 ], 2 )
94
+ # Only returns x1 and x2
95
+ @test all ([v in [:x1 , :x1x2f1 , :x2 ] for v in map (n -> n. label, [ls (dfgSubgraph)... , lsf (dfgSubgraph)... ])])
96
+ # Test include orphan factorsVoid
97
+ dfgSubgraph = getSubgraphAroundNode (dfg, verts[1 ], 1 , true )
98
+ @test all ([v in [:x1 , :x1x2f1 ] for v in map (n -> n. label, [ls (dfgSubgraph)... , lsf (dfgSubgraph)... ])])
99
+ # Test adding to the dfg
100
+ dfgSubgraph = getSubgraphAroundNode (dfg, verts[1 ], 2 , true , dfgSubgraph)
101
+ @test all ([v in [:x1 , :x1x2f1 , :x2 ] for v in map (n -> n. label, [ls (dfgSubgraph)... , lsf (dfgSubgraph)... ])])
95
102
end
0 commit comments