@@ -3,102 +3,11 @@ using DataFrames
3
3
using DistributedFactorGraphs
4
4
using DistributedFactorGraphs. GraphsJl
5
5
6
- dfg = GraphsDFG ()
7
- v1 = DFGVariable (:a )
8
- v2 = DFGVariable (:b )
9
- f1 = DFGFactor (:f1 )
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
18
-
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
27
-
28
- # Gets
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" )
37
-
38
- # Sets
39
- v1Prime = deepcopy (v1)
40
- @test updateVariable! (dfg, v1Prime) != v1
41
- f1Prime = deepcopy (f1)
42
- @test updateFactor! (dfg, f1Prime) != f1
43
- end
44
-
45
- # Deletions
46
- # Not supported at present
47
- @testset " Deletions" begin
48
- @warn " Deletions with Graph.jl is not supported at present"
49
- end
50
-
51
- # Connectivity test
52
- @testset " Connectivity Test" begin
53
- global dfg,v1,v2,f1
54
- @test isFullyConnected (dfg) == true
55
- @test hasOrphans (dfg) == false
56
- addVariable! (dfg, DFGVariable (:orphan ))
57
- @test isFullyConnected (dfg) == false
58
- @test hasOrphans (dfg) == true
59
- end
60
-
61
- # Adjacency matrices
62
- @testset " Adjacency Matrices" begin
63
- global dfg,v1,v2,f1
64
- # Normal
65
- adjMat = getAdjacencyMatrix (dfg)
66
- @test size (adjMat) == (2 ,4 )
67
- @test adjMat[1 , :] == [nothing , :a , :b , :orphan ]
68
- @test adjMat[2 , :] == [:f1 , :f1 , :f1 , nothing ]
69
- # Dataframe
70
- adjDf = getAdjacencyMatrixDataFrame (dfg)
71
- @test size (adjDf) == (1 ,4 )
72
- end
73
-
74
- # Now make a complex graph for connectivity tests
75
- numNodes = 10
76
- dfg = GraphsDFG ()
77
- verts = map (n -> DFGVariable (Symbol (" x$n " )), 1 : numNodes)
78
- map (v -> addVariable! (dfg, v), verts)
79
- map (n -> addFactor! (dfg, DFGFactor (Symbol (" x$(n) x$(n+ 1 ) f1" )), [verts[n], verts[n+ 1 ]]), 1 : (numNodes- 1 ))
80
- # map(n -> addFactor!(dfg, [verts[n], verts[n+2]], DFGFactor(Symbol("x$(n)x$(n+2)f2"))), 1:2:(numNodes-2))
81
-
82
- @testset " Getting Neighbors" begin
83
- global dfg,verts
84
- # Get neighbors tests
85
- @test getNeighbors (dfg, verts[1 ]) == [:x1x2f1 ]
86
- neighbors = getNeighbors (dfg, getFactor (dfg, :x1x2f1 ))
87
- @test all ([v in [:x1 , :x2 ] for v in neighbors])
88
- # Testing aliases
89
- @test getNeighbors (dfg, getFactor (dfg, :x1x2f1 )) == ls (dfg, getFactor (dfg, :x1x2f1 ))
90
- @test getNeighbors (dfg, :x1x2f1 ) == ls (dfg, :x1x2f1 )
91
- end
92
-
93
- @testset " Getting Subgraphs" begin
94
- # Subgraphs
95
- dfgSubgraph = getSubgraphAroundNode (dfg, verts[1 ], 2 )
96
- # Only returns x1 and x2
97
- @test setdiff ([:x1 , :x1x2f1 , :x2 ], map (n -> n. label, [ls (dfgSubgraph)... , lsf (dfgSubgraph)... ])) == []
98
- # Test include orphan factorsVoid
99
- dfgSubgraph = getSubgraphAroundNode (dfg, verts[1 ], 1 , true )
100
- @test setdiff ([:x1 , :x1x2f1 ], map (n -> n. label, [ls (dfgSubgraph)... , lsf (dfgSubgraph)... ])) == []
101
- # Test adding to the dfg
102
- dfgSubgraph = getSubgraphAroundNode (dfg, verts[1 ], 2 , true , dfgSubgraph)
103
- @test setdiff ([:x1 , :x1x2f1 , :x2 ], map (n -> n. label, [ls (dfgSubgraph)... , lsf (dfgSubgraph)... ])) == []
104
- end
6
+ # Test each interface
7
+ apis = [GraphsDFG]
8
+ global testDFGAPI = nothing
9
+ for api in apis
10
+ global testDFGAPI = api
11
+ include (" interfaceTests.jl" )
12
+ end
13
+ # Test other interfaces
0 commit comments