3
3
# using DistributedFactorGraphs
4
4
# using IncrementalInference
5
5
# using Test
6
- # testDFGAPI = CloudGraphsDFG
6
+ # dfg = apis[1]
7
7
8
- if typeof (dfg) == CloudGraphsDFG
8
+ global dfg,v1,v2,f1
9
+
10
+ if typeof (dfg) <: CloudGraphsDFG
11
+ @warn " TEST: Nuking all data for robot $(dfg. robotId) !"
9
12
clearRobot!! (dfg)
10
13
end
11
14
12
-
13
- v1 = addVariable! (dfg, :a , ContinuousScalar, labels = [:POSE ])
14
- v2 = addVariable! (dfg, :b , ContinuousScalar, labels = [:LANDMARK ])
15
- f1 = addFactor! (dfg, [:a ; :b ], LinearConditional (Normal (50.0 ,2.0 )) )
16
- # f1 = addFactor!(fg,[:x0], Prior( pd ) )
17
-
18
- # @testset "Creating Graphs" begin
19
- global dfg,v1,v2,f1
20
-
21
- @test_throws Exception addFactor! (dfg, DFGFactor {Int, :Symbol} (" f2" ), [v1, DFGVariable (" Nope" )])
22
- # 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
23
25
24
26
# test before anything changes
25
27
@testset " Producing Dot Files" begin
26
-
27
- @test toDot (dfg) == " 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 "
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)
28
34
@test toDotFile (dfg, " something.dot" ) == nothing
29
35
Base. rm (" something.dot" )
30
-
31
36
end
32
37
33
- @testset " Adding Removing Nodes" begin
34
- # TODO should errors vs updates be consistant between DFG types
35
- if typeof (dfg) != CloudGraphsDFG
36
- dfg2 = DistributedFactorGraphs. _getDuplicatedEmptyDFG (dfg)
37
- v1 = DFGVariable (:a )
38
- v2 = DFGVariable (:b )
39
- v3 = DFGVariable (:c )
40
- f1 = DFGFactor {ContinuousScalar, :Symbol} (:abf1 )
41
- f2 = DFGFactor {ContinuousScalar, :Symbol} (:f2 )
42
- # @testset "Creating Graphs" begin
43
- @test addVariable! (dfg2, v1)
44
- @test addVariable! (dfg2, v2)
45
- @test_throws ErrorException updateVariable! (dfg2, v3)
46
- @test addVariable! (dfg2, v3)
47
- @test_throws ErrorException addVariable! (dfg2, v3)
48
- @test addFactor! (dfg2, [v1, v2], f1)
49
- @test_throws ErrorException addFactor! (dfg2, [v1, v2], f1)
50
- @test_throws ErrorException updateFactor! (dfg2, f2)
51
- @test addFactor! (dfg2, [:b , :c ], f2)
52
- @test deleteVariable! (dfg2, v3) == v3
53
- @test symdiff (ls (dfg2),[:a ,:b ]) == []
54
- @test deleteFactor! (dfg2, f2) == f2
55
- @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 ())
56
51
else
57
- dfg2 = DistributedFactorGraphs. _getDuplicatedEmptyDFG (dfg)
58
- v1 = DFGVariable (:a )
59
- v2 = DFGVariable (:b )
60
- v3 = DFGVariable (:c )
61
- f1 = DFGFactor {ContinuousScalar, :Symbol} (:abf1 )
62
- f2 = DFGFactor {ContinuousScalar, :Symbol} (:f2 )
63
-
64
- @test addVariable! (dfg2, v1)
65
- @test addVariable! (dfg2, v2)
66
- @test_throws ErrorException updateVariable! (dfg2, v3)
67
- @test addVariable! (dfg2, v3)
68
- @test_skip @test_throws ErrorException addVariable! (dfg2, v3)
69
- @test_skip addFactor! (dfg2, [v1, v2], f1)
70
- @test_skip @test_throws ErrorException addFactor! (dfg2, [v1, v2], f1)
71
- @test_skip @test_throws ErrorException updateFactor! (dfg2, f2)
72
- @test_skip addFactor! (dfg2, [:b , :c ], f2)
73
- @test deleteVariable! (dfg2, v3) == v3 # FIXME ? one returns nothing other ""
74
- @test symdiff (ls (dfg2),[:a ,:b ]) == []
75
- @test_skip deleteFactor! (dfg2, f2) == f2
76
- @test_skip lsf (dfg2) == [:abf1 ]
52
+ dfg2 = T ()
77
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
+
78
88
end
79
89
80
90
@testset " Listing Nodes" begin
81
91
global dfg,v1,v2,f1
82
92
@test length (ls (dfg)) == 2
83
- @test length (lsf (dfg)) == 1
93
+ @test length (lsf (dfg)) == 1 # Unless we add the prior!
84
94
@test symdiff ([:a , :b ], getVariableIds (dfg)) == []
85
- @test getFactorIds (dfg) == [:abf1 ]
95
+ @test getFactorIds (dfg) == [:abf1 ] # Unless we add the prior!
86
96
#
87
97
@test lsf (dfg, :a ) == [f1. label]
88
98
# Tags
89
99
@test ls (dfg, tags= [:POSE ]) == [:a ]
90
100
@test symdiff (ls (dfg, tags= [:POSE , :LANDMARK ]), ls (dfg, tags= [:VARIABLE ])) == []
91
101
# Regexes
92
102
@test ls (dfg, r" a" ) == [v1. label]
93
- @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
+
94
108
# Accessors
95
109
@test getAddHistory (dfg) == [:a , :b ] # , :abf1
96
110
@test getDescription (dfg) != nothing
109
123
# Gets
110
124
@testset " Gets, Sets, and Accessors" begin
111
125
global dfg,v1,v2,f1
126
+ # TODO write compare for variable and factor it looks to be the same
112
127
@test getVariable (dfg, v1. label) == v1
113
128
@test getFactor (dfg, f1. label) == f1
114
129
@test_throws Exception getVariable (dfg, :nope )
@@ -241,11 +256,11 @@ end
241
256
242
257
# Now make a complex graph for connectivity tests
243
258
numNodes = 10
244
-
245
- dfg = DistributedFactorGraphs. _getDuplicatedEmptyDFG (dfg)
246
- if typeof (dfg) == CloudGraphsDFG
247
- clearSession!! (dfg)
248
- 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
249
264
250
265
# change ready and backendset for x7,x8 for improved tests on x7x8f1
251
266
verts = map (n -> addVariable! (dfg, Symbol (" x$n " ), ContinuousScalar, labels = [:POSE ]), 1 : numNodes)
@@ -254,6 +269,9 @@ verts[7].ready = 1
254
269
# verts[7].backendset = 0
255
270
verts[8 ]. ready = 0
256
271
verts[8 ]. backendset = 1
272
+ # call update to set it on cloud
273
+ updateVariable! (dfg, verts[7 ])
274
+ updateVariable! (dfg, verts[8 ])
257
275
258
276
facts = map (n -> addFactor! (dfg, [verts[n], verts[n+ 1 ]], LinearConditional (Normal (50.0 ,2.0 ))), 1 : (numNodes- 1 ))
259
277
@@ -273,9 +291,10 @@ facts = map(n -> addFactor!(dfg, [verts[n], verts[n+1]], LinearConditional(Norma
273
291
274
292
# ready and backendset
275
293
@test getNeighbors (dfg, :x5 , ready= 1 ) == Symbol[]
276
- @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 ]) == []
277
296
@test getNeighbors (dfg, :x5 , backendset= 1 ) == Symbol[]
278
- @test getNeighbors (dfg, :x5 , backendset= 0 ) == [:x4x5f1 ,:x5x6f1 ]
297
+ @test symdiff ( getNeighbors (dfg, :x5 , backendset= 0 ), [:x4x5f1 ,:x5x6f1 ]) == [ ]
279
298
@test getNeighbors (dfg, :x7x8f1 , ready= 0 ) == [:x8 ]
280
299
@test getNeighbors (dfg, :x7x8f1 , backendset= 0 ) == [:x7 ]
281
300
@test getNeighbors (dfg, :x7x8f1 , ready= 1 ) == [:x7 ]
0 commit comments