Skip to content

Commit 10978ed

Browse files
authored
Merge pull request #171 from JuliaRobotics/feature/FileDFG_testing
FileDFG testing
2 parents 83274f2 + 3bc4fc8 commit 10978ed

File tree

5 files changed

+73
-84
lines changed

5 files changed

+73
-84
lines changed

src/FileDFG/services/FileDFG.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function saveDFG(dfg::G, folder::String) where G <: AbstractDFG
3030
end
3131
end
3232

33-
function loadDFG(folder::String, iifModule, dfgLoadInto::G=GraphsDFG{NoSolverParams}()) where G <: AbstractDFG
33+
function loadDFG(folder::String, iifModule, dfgLoadInto::G) where G <: AbstractDFG
3434
variables = DFGVariable[]
3535
factors = DFGFactor[]
3636
varFolder = "$folder/variables"
@@ -70,9 +70,8 @@ function loadDFG(folder::String, iifModule, dfgLoadInto::G=GraphsDFG{NoSolverPar
7070

7171
# PATCH - To update the fncargvID for factors, it's being cleared somewhere in rebuildFactorMetadata.
7272
# TEMPORARY
73-
# TODO: Remove
73+
# TODO: Remove in future
7474
map(f->solverData(f).fncargvID = f._variableOrderSymbols, getFactors(dfgLoadInto))
7575

76-
7776
return dfgLoadInto
7877
end

test/fileDFGTests.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@testset "FileDFG Tests" begin
2+
3+
if typeof(dfg) <: CloudGraphsDFG
4+
@warn "TEST: Nuking all data for user '$(dfg.userId)', robot '$(dfg.robotId)'!"
5+
clearRobot!!(dfg)
6+
end
7+
8+
# Same graph as iifInterfaceTests.jl
9+
numNodes = 10
10+
11+
#change ready and backendset for x7,x8 for improved tests on x7x8f1
12+
verts = map(n -> addVariable!(dfg, Symbol("x$n"), ContinuousScalar, labels = [:POSE]), 1:numNodes)
13+
#TODO fix this to use accessors
14+
verts[7].ready = 1
15+
# verts[7].backendset = 0
16+
verts[8].ready = 0
17+
verts[8].backendset = 1
18+
#call update to set it on cloud
19+
updateVariable!(dfg, verts[7])
20+
updateVariable!(dfg, verts[8])
21+
22+
facts = map(n -> addFactor!(dfg, [verts[n], verts[n+1]], LinearConditional(Normal(50.0,2.0))), 1:(numNodes-1))
23+
24+
# Save and load the graph to test.
25+
saveFolder = "/tmp/fileDFG"
26+
saveDFG(dfg, saveFolder)
27+
28+
copyDfg = DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg)
29+
retDFG = loadDFG(saveFolder, Main, copyDfg)
30+
@test symdiff(ls(dfg), ls(retDFG)) == []
31+
@test symdiff(lsf(dfg), lsf(retDFG)) == []
32+
for var in ls(dfg)
33+
@test getVariable(dfg, var) == getVariable(retDFG, var)
34+
end
35+
for fact in lsf(dfg)
36+
@test getFactor(dfg, fact) == getFactor(retDFG, fact)
37+
end
38+
end

test/obsolete_nowinRoME/FileDFG.jl

Lines changed: 0 additions & 54 deletions
This file was deleted.

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ if get(ENV, "IIF_TEST", "") == "true"
7373
global dfg = deepcopy(api)
7474
include("iifInterfaceTests.jl")
7575
end
76+
77+
@testset "FileDFG Testing Driver: $(typeof(api))" begin
78+
@info "FileDFG Testing Driver: $(typeof(api))"
79+
global dfg = deepcopy(api)
80+
include("fileDFGTests.jl")
81+
end
7682
end
7783
else
7884
@warn "Skipping IncrementalInference driver tests"

test/sandbox.jl

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
# using Revise
2+
# using Neo4j
3+
4+
# Debug logging
5+
# using DistributedFactorGraphs
6+
using Test
7+
using Logging
28
using Neo4j
39
using DistributedFactorGraphs
410
using IncrementalInference
5-
using Test
6-
using Logging
7-
# Debug logging
811
logger = SimpleLogger(stdout, Logging.Debug)
912
global_logger(logger)
1013

1114
dfg = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
12-
"testUser", "testRobot", "sandbox",
15+
"testUser", "testRobot", "testSession",
1316
nothing,
1417
nothing,
1518
IncrementalInference.decodePackedType,
1619
IncrementalInference.rebuildFactorMetadata!,
1720
solverParams=SolverParams())
18-
clearRobot!!(dfg)
1921

22+
if typeof(dfg) <: CloudGraphsDFG
23+
@warn "TEST: Nuking all data for user '$(dfg.userId)', robot '$(dfg.robotId)'!"
24+
clearRobot!!(dfg)
25+
end
26+
27+
# Same graph as iifInterfaceTests.jl
2028
numNodes = 10
29+
2130
#change ready and backendset for x7,x8 for improved tests on x7x8f1
2231
verts = map(n -> addVariable!(dfg, Symbol("x$n"), ContinuousScalar, labels = [:POSE]), 1:numNodes)
2332
#TODO fix this to use accessors
@@ -31,25 +40,16 @@ updateVariable!(dfg, verts[8])
3140

3241
facts = map(n -> addFactor!(dfg, [verts[n], verts[n+1]], LinearConditional(Normal(50.0,2.0))), 1:(numNodes-1))
3342

34-
# Get neighbors tests
35-
@test getNeighbors(dfg, verts[1]) == [:x1x2f1]
36-
neighbors = getNeighbors(dfg, getFactor(dfg, :x1x2f1))
37-
@test neighbors == [:x1, :x2]
38-
# Testing aliases
39-
@test getNeighbors(dfg, getFactor(dfg, :x1x2f1)) == ls(dfg, getFactor(dfg, :x1x2f1))
40-
@test getNeighbors(dfg, :x1x2f1) == ls(dfg, :x1x2f1)
41-
42-
# ready and backendset
43-
@test getNeighbors(dfg, :x5, ready=1) == Symbol[]
44-
#TODO Confirm: test failed on GraphsDFG, don't know if the order is important for isa variable.
45-
@test symdiff(getNeighbors(dfg, :x5, ready=0), [:x4x5f1,:x5x6f1]) == []
46-
@test getNeighbors(dfg, :x5, backendset=1) == Symbol[]
47-
@test symdiff(getNeighbors(dfg, :x5, backendset=0),[:x4x5f1,:x5x6f1]) == []
48-
@test getNeighbors(dfg, :x7x8f1, ready=0) == [:x8]
49-
@test getNeighbors(dfg, :x7x8f1, backendset=0) == [:x7]
50-
@test getNeighbors(dfg, :x7x8f1, ready=1) == [:x7]
51-
@test getNeighbors(dfg, :x7x8f1, backendset=1) == [:x8]
52-
@test getNeighbors(dfg, verts[1], ready=0) == [:x1x2f1]
53-
@test getNeighbors(dfg, verts[1], ready=1) == Symbol[]
54-
@test getNeighbors(dfg, verts[1], backendset=0) == [:x1x2f1]
55-
@test getNeighbors(dfg, verts[1], backendset=1) == Symbol[]
43+
# Save and load the graph to test.
44+
saveFolder = "/tmp/fileDFG"
45+
saveDFG(dfg, saveFolder)
46+
47+
retDFG = loadDFG(saveFolder, Main)
48+
@test symdiff(ls(dfg), ls(retDFG)) == []
49+
@test symdiff(lsf(dfg), lsf(retDFG)) == []
50+
for var in ls(dfg)
51+
@test getVariable(dfg, var) == getVariable(retDFG, var)
52+
end
53+
for fact in lsf(dfg)
54+
@test getFactor(dfg, fact) == getFactor(retDFG, fact)
55+
end

0 commit comments

Comments
 (0)