Skip to content

Commit 99c55b3

Browse files
committed
merged iifinterfaceTests.jl
1 parent 5ef922a commit 99c55b3

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

test/iifInterfaceTests.jl

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
global dfg,v1,v2,f1
99

1010
if typeof(dfg) <: CloudGraphsDFG
11-
@warn "TEST: Nuking all data for robot $(dfg.robotId)!"
11+
@warn "TEST: Nuking all data for user '$(dfg.userId)', robot '$(dfg.robotId)'!"
1212
clearRobot!!(dfg)
1313
end
1414

@@ -52,14 +52,15 @@ end
5252
dfg2 = T()
5353
end
5454

55+
# Build a new in-memory IIF graph to transfer into the new graph.
5556
iiffg = initfg()
5657
v1 = deepcopy(addVariable!(iiffg, :a, ContinuousScalar))
5758
v2 = deepcopy(addVariable!(iiffg, :b, ContinuousScalar))
5859
v3 = deepcopy(addVariable!(iiffg, :c, ContinuousScalar))
5960
f1 = deepcopy(addFactor!(iiffg, [:a; :b], LinearConditional(Normal(50.0,2.0)) ))
6061
f2 = deepcopy(addFactor!(iiffg, [:b; :c], LinearConditional(Normal(10.0,1.0)) ))
6162

62-
# @testset "Creating Graphs" begin
63+
# Add it to the new graph.
6364
@test addVariable!(dfg2, v1)
6465
@test addVariable!(dfg2, v2)
6566
@test_throws ErrorException updateVariable!(dfg2, v3)
@@ -123,7 +124,6 @@ end
123124
# Gets
124125
@testset "Gets, Sets, and Accessors" begin
125126
global dfg,v1,v2,f1
126-
#TODO write compare for variable and factor it looks to be the same
127127
@test getVariable(dfg, v1.label) == v1
128128
@test getFactor(dfg, f1.label) == f1
129129
@test_throws Exception getVariable(dfg, :nope)
@@ -134,8 +134,10 @@ end
134134
# Sets
135135
v1Prime = deepcopy(v1)
136136
@test updateVariable!(dfg, v1Prime) != v1
137+
@test updateVariable!(dfg, v1Prime) == getVariable(dfg, v1.label)
137138
f1Prime = deepcopy(f1)
138139
@test updateFactor!(dfg, f1Prime) != f1
140+
#@test updateFactor!(dfg, f1Prime) == getFactor(dfg, f1.label)
139141

140142
# Accessors
141143
@test label(v1) == v1.label
@@ -228,7 +230,7 @@ end
228230
@test getBigDataKeys(v1) == Symbol[]
229231
end
230232

231-
@testset "Updating Nodes" begin
233+
@testset "Updating Nodes and Estimates" begin
232234
global dfg
233235
#get the variable
234236
var = getVariable(dfg, :a)
@@ -240,40 +242,43 @@ end
240242
:modefit => VariableEstimate(:default, :modefit, [75.0]))
241243
#update
242244
updateVariableSolverData!(dfg, newvar)
243-
#TODO maybe implement ==; @test newvar==var
244-
Base.:(==)(varest1::VariableEstimate, varest2::VariableEstimate) = begin
245-
varest1.lastUpdatedTimestamp == varest2.lastUpdatedTimestamp || return false
246-
varest1.ppeType == varest2.ppeType || return false
247-
varest1.solverKey == varest2.solverKey || return false
248-
varest1.estimate == varest2.estimate || return false
249-
return true
250-
end
245+
251246
#For now spot check
252247
@test_skip solverDataDict(newvar) == solverDataDict(var)
248+
var = getVariable(dfg, :a)
253249
@test estimates(newvar) == estimates(var)
254250

255-
# Delete :default and replace to see if new ones can be added
256-
delete!(estimates(newvar), :default)
251+
# Add a new estimate.
257252
estimates(newvar)[:second] = Dict{Symbol, VariableEstimate}(
258253
:max => VariableEstimate(:default, :max, [10.0]),
259254
:mean => VariableEstimate(:default, :mean, [5.0]),
260255
:modefit => VariableEstimate(:default, :modefit, [7.0]))
261256

262-
# Persist to the original variable.
257+
# Confirm they're different
258+
@test estimates(newvar) != estimates(var)
259+
# Persist it.
263260
updateVariableSolverData!(dfg, newvar)
261+
# Get the latest
262+
var = getVariable(dfg, :a)
264263
# At this point newvar will have only :second, and var should have both (it is the reference)
265264
@test symdiff(collect(keys(estimates(var))), [:default, :second]) == Symbol[]
265+
# Delete :default and replace to see if new ones can be added
266+
delete!(estimates(newvar), :default)
266267
@test symdiff(collect(keys(estimates(newvar))), [:second]) == Symbol[]
267-
# Get the source too.
268-
@test symdiff(collect(keys(estimates(getVariable(dfg, :a)))), [:default, :second]) == Symbol[]
268+
# Persist it.
269+
updateVariableSolverData!(dfg, newvar)
270+
# Get the latest and confirm they're the same, :second
271+
var = getVariable(dfg, :a)
272+
@test estimates(newvar) == estimates(var)
273+
@test collect(keys(estimates(var))) == [:second]
269274
end
270275

271276
# Connectivity test
272277
@testset "Connectivity Test" begin
273278
global dfg,v1,v2,f1
274279
@test isFullyConnected(dfg) == true
275280
@test hasOrphans(dfg) == false
276-
addVariable!(dfg, DFGVariable(:orphan))
281+
addVariable!(dfg, :orphan, ContinuousScalar, labels = [:POSE])
277282
@test isFullyConnected(dfg) == false
278283
@test hasOrphans(dfg) == true
279284
end

0 commit comments

Comments
 (0)