Skip to content

Commit 91f4046

Browse files
committed
Fixing tests
1 parent 6f76b68 commit 91f4046

File tree

3 files changed

+18
-30
lines changed

3 files changed

+18
-30
lines changed

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,6 @@ function updateVariable!(dfg::GraphsDFG, variable::DFGVariable)::DFGVariable
164164
return variable
165165
end
166166

167-
"""
168-
$(SIGNATURES)
169-
Update solver and estimate data for a variable (variable can be from another graph).
170-
"""
171-
function updateVariableSolverData!(dfg::GraphsDFG, sourceVariable::DFGVariable)::DFGVariable
172-
if !haskey(dfg.labelDict, sourceVariable.label)
173-
error("Source variable '$(sourceVariable.label)' doesn't exist in the graph.")
174-
end
175-
dfg.g.vertices[dfg.labelDict[sourceVariable.label]].dfgNode.estimateDict = deepcopy(sourceVariable.estimateDict)
176-
dfg.g.vertices[dfg.labelDict[sourceVariable.label]].dfgNode.solverDataDict = deepcopy(sourceVariable.solverDataDict)
177-
return sourceVariable
178-
end
179-
180167
"""
181168
$(SIGNATURES)
182169
Update a complete DFGFactor in the DFG.

src/services/AbstractDFG.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,17 @@ end
7070
"""
7171
$(SIGNATURES)
7272
Update solver and estimate data for a variable (variable can be from another graph).
73+
Note: Makes a copy of the estimates and solver data so that there is no coupling
74+
between graphs.
7375
"""
7476
function updateVariableSolverData!(dfg::AbstractDFG, sourceVariable::DFGVariable)::DFGVariable
7577
if !exists(dfg, sourceVariable)
7678
error("Source variable '$(sourceVariable.label)' doesn't exist in the graph.")
7779
end
7880
var = getVariable(dfg, sourceVariable.label)
79-
merge!(var.estimateDict, sourceVariable.estimateDict)
80-
merge!(var.solverDataDict, sourceVariable.solverDataDict)
81+
# We don't know which graph this came from, must be copied!
82+
merge!(var.estimateDict, deepcopy(sourceVariable.estimateDict))
83+
merge!(var.solverDataDict, deepcopy(sourceVariable.solverDataDict))
8184
return sourceVariable
8285
end
8386

test/interfaceTests.jl

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ addFactor!(dfg, [v1, v2], f1)
1717
# end
1818

1919
@testset "Adding Removing Nodes" begin
20-
dfg2 = testDFGAPI{NoSolverParams}()
20+
dfg2 = GraphsDFG{NoSolverParams}()
2121
v1 = DFGVariable(:a)
2222
v2 = DFGVariable(:b)
2323
v3 = DFGVariable(:c)
@@ -100,7 +100,7 @@ end
100100
var = getVariable(dfg, :a)
101101
#make a copy and simulate external changes
102102
newvar = deepcopy(var)
103-
newvar.estimateDict[:default] = Dict{Symbol, VariableEstimate}(
103+
estimates(newvar)[:default] = Dict{Symbol, VariableEstimate}(
104104
:max => VariableEstimate(:default, :max, [100.0]),
105105
:mean => VariableEstimate(:default, :mean, [50.0]),
106106
:ppe => VariableEstimate(:default, :ppe, [75.0]))
@@ -115,25 +115,23 @@ end
115115
return true
116116
end
117117
#For now spot check
118-
@test newvar.solverDataDict == var.solverDataDict
119-
@test newvar.estimateDict == var.estimateDict
118+
@test solverDataDict(newvar) == solverDataDict(var)
119+
@test estimates(newvar) == estimates(var)
120120

121-
#delete :default and replace to see if new ones can be added
122-
delete!(newvar.estimateDict,:default)
123-
newvar.estimateDict[:second] = Dict{Symbol, VariableEstimate}(
121+
# Delete :default and replace to see if new ones can be added
122+
delete!(estimates(newvar), :default)
123+
estimates(newvar)[:second] = Dict{Symbol, VariableEstimate}(
124124
:max => VariableEstimate(:default, :max, [10.0]),
125125
:mean => VariableEstimate(:default, :mean, [5.0]),
126126
:ppe => VariableEstimate(:default, :ppe, [7.0]))
127127

128+
# Persist to the original variable.
128129
updateVariableSolverData!(dfg, newvar)
129-
130-
#FIXME
131-
if testDFGAPI != GraphsDFG
132-
@test symdiff(collect(keys(var.estimateDict)),Symbol[:default, :second]) == Symbol[]
133-
else
134-
@error "FIXME: $(keys(var.estimateDict)) should be [:default, :second]"
135-
@test_skip symdiff(collect(keys(var.estimateDict)),Symbol[:default, :second]) == Symbol[]
136-
end
130+
# At this point newvar will have only :second, and var should have both (it is the reference)
131+
@test symdiff(collect(keys(estimates(var))), [:default, :second]) == Symbol[]
132+
@test symdiff(collect(keys(estimates(newvar))), [:second]) == Symbol[]
133+
# Get the source too.
134+
@test symdiff(collect(keys(estimates(getVariable(dfg, :a)))), [:default, :second]) == Symbol[]
137135
end
138136

139137
# Connectivity test

0 commit comments

Comments
 (0)