3
3
# using DistributedFactorGraphs
4
4
# using IncrementalInference
5
5
# using Test
6
- # testDFGAPI = CloudGraphsDFG
7
-
8
- if testDFGAPI == CloudGraphsDFG
9
- DistributedFactorGraphs. CloudGraphsDFG {SolverParams} () = CloudGraphsDFG {SolverParams} (" localhost" , 7474 , " neo4j" , " test" ,
10
- " testUser" , " testRobot" , " testSession" ,
11
- nothing ,
12
- nothing ,
13
- IncrementalInference. decodePackedType,
14
- IncrementalInference. rebuildFactorMetadata!,
15
- solverParams= SolverParams ())
6
+ # dfg = apis[1]
16
7
8
+ global dfg,v1,v2,f1
17
9
18
- dfg = testDFGAPI {SolverParams} ()
10
+ if typeof (dfg) <: CloudGraphsDFG
11
+ @warn " TEST: Nuking all data for robot $(dfg. robotId) !"
19
12
clearRobot!! (dfg)
20
- else
21
- dfg = testDFGAPI {NoSolverParams} ()
22
13
end
23
14
24
-
25
- v1 = addVariable! (dfg, :a , ContinuousScalar, labels = [:POSE ])
26
- v2 = addVariable! (dfg, :b , ContinuousScalar, labels = [:LANDMARK ])
27
- f1 = addFactor! (dfg, [:a ; :b ], LinearConditional (Normal (50.0 ,2.0 )) )
28
- # f1 = addFactor!(fg,[:x0], Prior( pd ) )
29
-
30
- # @testset "Creating Graphs" begin
31
- global dfg,v1,v2,f1
32
-
33
- @test_throws Exception addFactor! (dfg, DFGFactor {Int, :Symbol} (" f2" ), [v1, DFGVariable (" Nope" )])
34
- # end
15
+ # Building simple graph...
16
+ @testset " Building a simple Graph" begin
17
+ global dfg,v1,v2,f1
18
+ # Use IIF to add the variables and factors
19
+ v1 = addVariable! (dfg, :a , ContinuousScalar, labels = [:POSE ])
20
+ v2 = addVariable! (dfg, :b , ContinuousScalar, labels = [:LANDMARK ])
21
+ f1 = addFactor! (dfg, [:a ; :b ], LinearConditional (Normal (50.0 ,2.0 )) )
22
+ # f1 = addFactor!(fg,[:x0], Prior( pd ) )
23
+ # @test_throws Exception addFactor!(dfg, DFGFactor{Int, :Symbol}("f2"), [v1, DFGVariable("Nope")])
24
+ end
35
25
36
26
# test before anything changes
37
27
@testset " Producing Dot Files" begin
38
-
39
- @test toDot (dfg) == " graph graphname {\n 2 [\" label\" =\" b\" ,\" shape\" =\" box\" ,\" fillcolor\" =\" red\" ,\" color\" =\" red\" ]\n 2 -- 3\n 3 [\" label\" =\" abf1\" ,\" shape\" =\" ellipse\" ,\" fillcolor\" =\" blue\" ,\" color\" =\" blue\" ]\n 1 [\" label\" =\" a\" ,\" shape\" =\" box\" ,\" fillcolor\" =\" red\" ,\" color\" =\" red\" ]\n 1 -- 3\n }\n "
28
+ global dfg
29
+ todotstr = toDot (dfg)
30
+ # TODO consider using a regex, but for now test both orders
31
+ todota = todotstr == " graph graphname {\n 2 [\" label\" =\" a\" ,\" shape\" =\" ellipse\" ,\" fillcolor\" =\" red\" ,\" color\" =\" red\" ]\n 2 -- 3\n 3 [\" label\" =\" abf1\" ,\" shape\" =\" box\" ,\" fillcolor\" =\" blue\" ,\" color\" =\" blue\" ]\n 1 [\" label\" =\" b\" ,\" shape\" =\" ellipse\" ,\" fillcolor\" =\" red\" ,\" color\" =\" red\" ]\n 1 -- 3\n }\n "
32
+ todotb = todotstr == " graph graphname {\n 2 [\" label\" =\" b\" ,\" shape\" =\" ellipse\" ,\" fillcolor\" =\" red\" ,\" color\" =\" red\" ]\n 2 -- 3\n 3 [\" label\" =\" abf1\" ,\" shape\" =\" box\" ,\" fillcolor\" =\" blue\" ,\" color\" =\" blue\" ]\n 1 [\" label\" =\" a\" ,\" shape\" =\" ellipse\" ,\" fillcolor\" =\" red\" ,\" color\" =\" red\" ]\n 1 -- 3\n }\n "
33
+ @test (todota || todotb)
40
34
@test toDotFile (dfg, " something.dot" ) == nothing
41
35
Base. rm (" something.dot" )
42
-
43
36
end
44
37
45
- @testset " Adding Removing Nodes" begin
46
- # TODO should errors vs updates be consistant between DFG types
47
- if testDFGAPI != CloudGraphsDFG
48
- dfg2 = testDFGAPI {NoSolverParams} ()
49
- v1 = DFGVariable (:a )
50
- v2 = DFGVariable (:b )
51
- v3 = DFGVariable (:c )
52
- f1 = DFGFactor {ContinuousScalar, :Symbol} (:abf1 )
53
- f2 = DFGFactor {ContinuousScalar, :Symbol} (:f2 )
54
- # @testset "Creating Graphs" begin
55
- @test addVariable! (dfg2, v1)
56
- @test addVariable! (dfg2, v2)
57
- @test_throws ErrorException updateVariable! (dfg2, v3)
58
- @test addVariable! (dfg2, v3)
59
- @test_throws ErrorException addVariable! (dfg2, v3)
60
- @test addFactor! (dfg2, [v1, v2], f1)
61
- @test_throws ErrorException addFactor! (dfg2, [v1, v2], f1)
62
- @test_throws ErrorException updateFactor! (dfg2, f2)
63
- @test addFactor! (dfg2, [:b , :c ], f2)
64
- @test deleteVariable! (dfg2, v3) == v3
65
- @test symdiff (ls (dfg2),[:a ,:b ]) == []
66
- @test deleteFactor! (dfg2, f2) == f2
67
- @test lsf (dfg2) == [:abf1 ]
38
+ @testset " Testing CRUD, return and Failures from a GraphsDFG" begin
39
+ global dfg
40
+ # fg to copy to
41
+ # creating a whole new graph with the same labels
42
+ T = typeof (dfg)
43
+ if T <: CloudGraphsDFG
44
+ dfg2 = CloudGraphsDFG {SolverParams} (" localhost" , 7474 , " neo4j" , " test" ,
45
+ " testUser" , " testRobot" , " testSession2" ,
46
+ nothing ,
47
+ nothing ,
48
+ IncrementalInference. decodePackedType,
49
+ IncrementalInference. rebuildFactorMetadata!,
50
+ solverParams= SolverParams ())
68
51
else
69
- dfg2 = testDFGAPI {SolverParams} ()
70
- v1 = DFGVariable (:a )
71
- v2 = DFGVariable (:b )
72
- v3 = DFGVariable (:c )
73
- f1 = DFGFactor {ContinuousScalar, :Symbol} (:abf1 )
74
- f2 = DFGFactor {ContinuousScalar, :Symbol} (:f2 )
75
-
76
- @test addVariable! (dfg2, v1)
77
- @test addVariable! (dfg2, v2)
78
- @test_throws ErrorException updateVariable! (dfg2, v3)
79
- @test addVariable! (dfg2, v3)
80
- @test_skip @test_throws ErrorException addVariable! (dfg2, v3)
81
- @test_skip addFactor! (dfg2, [v1, v2], f1)
82
- @test_skip @test_throws ErrorException addFactor! (dfg2, [v1, v2], f1)
83
- @test_skip @test_throws ErrorException updateFactor! (dfg2, f2)
84
- @test_skip addFactor! (dfg2, [:b , :c ], f2)
85
- @test deleteVariable! (dfg2, v3) == v3 # FIXME ? one returns nothing other ""
86
- @test symdiff (ls (dfg2),[:a ,:b ]) == []
87
- @test_skip deleteFactor! (dfg2, f2) == f2
88
- @test_skip lsf (dfg2) == [:abf1 ]
52
+ dfg2 = T ()
89
53
end
54
+
55
+ iiffg = initfg ()
56
+ v1 = deepcopy (addVariable! (iiffg, :a , ContinuousScalar))
57
+ v2 = deepcopy (addVariable! (iiffg, :b , ContinuousScalar))
58
+ v3 = deepcopy (addVariable! (iiffg, :c , ContinuousScalar))
59
+ f1 = deepcopy (addFactor! (iiffg, [:a ; :b ], LinearConditional (Normal (50.0 ,2.0 )) ))
60
+ f2 = deepcopy (addFactor! (iiffg, [:b ; :c ], LinearConditional (Normal (10.0 ,1.0 )) ))
61
+
62
+ # @testset "Creating Graphs" begin
63
+ @test addVariable! (dfg2, v1)
64
+ @test addVariable! (dfg2, v2)
65
+ @test_throws ErrorException updateVariable! (dfg2, v3)
66
+ @test addVariable! (dfg2, v3)
67
+ @test_throws ErrorException addVariable! (dfg2, v3)
68
+ @test addFactor! (dfg2, [v1, v2], f1)
69
+ @test_throws ErrorException addFactor! (dfg2, [v1, v2], f1)
70
+ @test_throws ErrorException updateFactor! (dfg2, f2)
71
+ @test addFactor! (dfg2, [:b , :c ], f2)
72
+
73
+ dv3 = deleteVariable! (dfg2, v3)
74
+ # TODO write compare if we want to compare complete one, for now just label
75
+ # @test dv3 == v3
76
+ @test dv3. label == v3. label
77
+ @test_throws ErrorException deleteVariable! (dfg2, v3)
78
+
79
+ @test symdiff (ls (dfg2),[:a ,:b ]) == []
80
+ df2 = deleteFactor! (dfg2, f2)
81
+ # TODO write compare if we want to compare complete one, for now just label
82
+ # @test df2 == f2
83
+ @test df2. label == f2. label
84
+ @test_throws ErrorException deleteFactor! (dfg2, f2)
85
+
86
+ @test lsf (dfg2) == [:abf1 ]
87
+
90
88
end
91
89
92
90
@testset " Listing Nodes" begin
93
91
global dfg,v1,v2,f1
94
92
@test length (ls (dfg)) == 2
95
- @test length (lsf (dfg)) == 1
93
+ @test length (lsf (dfg)) == 1 # Unless we add the prior!
96
94
@test symdiff ([:a , :b ], getVariableIds (dfg)) == []
97
- @test getFactorIds (dfg) == [:abf1 ]
95
+ @test getFactorIds (dfg) == [:abf1 ] # Unless we add the prior!
98
96
#
99
97
@test lsf (dfg, :a ) == [f1. label]
100
98
# Tags
101
99
@test ls (dfg, tags= [:POSE ]) == [:a ]
102
100
@test symdiff (ls (dfg, tags= [:POSE , :LANDMARK ]), ls (dfg, tags= [:VARIABLE ])) == []
103
101
# Regexes
104
102
@test ls (dfg, r" a" ) == [v1. label]
105
- @test lsf (dfg, r" f*" ) == [f1. label]
103
+ # TODO : Check that this regular expression works on everything else!
104
+ # it works with the .
105
+ # REF: https://stackoverflow.com/questions/23834692/using-regular-expression-in-neo4j
106
+ @test lsf (dfg, r" abf.*" ) == [f1. label]
107
+
106
108
# Accessors
107
109
@test getAddHistory (dfg) == [:a , :b ] # , :abf1
108
110
@test getDescription (dfg) != nothing
121
123
# Gets
122
124
@testset " Gets, Sets, and Accessors" begin
123
125
global dfg,v1,v2,f1
126
+ # TODO write compare for variable and factor it looks to be the same
124
127
@test getVariable (dfg, v1. label) == v1
125
128
@test getFactor (dfg, f1. label) == f1
126
129
@test_throws Exception getVariable (dfg, :nope )
@@ -253,13 +256,11 @@ end
253
256
254
257
# Now make a complex graph for connectivity tests
255
258
numNodes = 10
256
-
257
- if testDFGAPI == CloudGraphsDFG
258
- dfg = testDFGAPI {SolverParams} ()
259
- clearRobot!! (dfg)
260
- else
261
- dfg = testDFGAPI {NoSolverParams} ()
262
- end
259
+ # the deletions in last test should have cleared out the fg
260
+ # dfg = DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg)
261
+ # if typeof(dfg) <: CloudGraphsDFG
262
+ # clearSession!!(dfg)
263
+ # end
263
264
264
265
# change ready and backendset for x7,x8 for improved tests on x7x8f1
265
266
verts = map (n -> addVariable! (dfg, Symbol (" x$n " ), ContinuousScalar, labels = [:POSE ]), 1 : numNodes)
@@ -268,6 +269,9 @@ verts[7].ready = 1
268
269
# verts[7].backendset = 0
269
270
verts[8 ]. ready = 0
270
271
verts[8 ]. backendset = 1
272
+ # call update to set it on cloud
273
+ updateVariable! (dfg, verts[7 ])
274
+ updateVariable! (dfg, verts[8 ])
271
275
272
276
facts = map (n -> addFactor! (dfg, [verts[n], verts[n+ 1 ]], LinearConditional (Normal (50.0 ,2.0 ))), 1 : (numNodes- 1 ))
273
277
@@ -287,9 +291,10 @@ facts = map(n -> addFactor!(dfg, [verts[n], verts[n+1]], LinearConditional(Norma
287
291
288
292
# ready and backendset
289
293
@test getNeighbors (dfg, :x5 , ready= 1 ) == Symbol[]
290
- @test getNeighbors (dfg, :x5 , ready= 0 ) == [:x4x5f1 ,:x5x6f1 ]
294
+ # TODO Confirm: test failed on GraphsDFG, don't know if the order is important for isa variable.
295
+ @test symdiff (getNeighbors (dfg, :x5 , ready= 0 ), [:x4x5f1 ,:x5x6f1 ]) == []
291
296
@test getNeighbors (dfg, :x5 , backendset= 1 ) == Symbol[]
292
- @test getNeighbors (dfg, :x5 , backendset= 0 ) == [:x4x5f1 ,:x5x6f1 ]
297
+ @test symdiff ( getNeighbors (dfg, :x5 , backendset= 0 ), [:x4x5f1 ,:x5x6f1 ]) == [ ]
293
298
@test getNeighbors (dfg, :x7x8f1 , ready= 0 ) == [:x8 ]
294
299
@test getNeighbors (dfg, :x7x8f1 , backendset= 0 ) == [:x7 ]
295
300
@test getNeighbors (dfg, :x7x8f1 , ready= 1 ) == [:x7 ]
0 commit comments