Skip to content

Commit 2dae9db

Browse files
committed
Improved tests and bug fixes tests caught
1 parent 4bd3b80 commit 2dae9db

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ end
195195
$(SIGNATURES)
196196
Delete a referenced DFGVariable from the DFG.
197197
"""
198-
deleteVariable!(dfg::GraphsDFG, variable::DFGVariable)::DFGVariable = deleteVariable(dfg, variable.label)
198+
deleteVariable!(dfg::GraphsDFG, variable::DFGVariable)::DFGVariable = deleteVariable!(dfg, variable.label)
199199

200200
"""
201201
$(SIGNATURES)
@@ -451,7 +451,7 @@ Get a deep subgraph copy from the DFG given a list of variables and factors.
451451
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
452452
Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
453453
"""
454-
function getSubgraph(dfg::GraphsDFG, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false, addToDFG::GraphsDFG=GraphsDFG())::GraphsDFG
454+
function getSubgraph(dfg::GraphsDFG, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false, addToDFG::GraphsDFG=GraphsDFG{AbstractParams}())::GraphsDFG
455455
for label in variableFactorLabels
456456
if !haskey(dfg.labelDict, label)
457457
error("Variable/factor with label '$(label)' does not exist in the factor graph")

src/LightGraphsDFG/services/LightGraphsDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ end
196196
$(SIGNATURES)
197197
Delete a referenced DFGVariable from the DFG.
198198
"""
199-
deleteVariable!(dfg::LightGraphsDFG, variable::DFGVariable)::DFGVariable = deleteVariable(dfg, variable.label)
199+
deleteVariable!(dfg::LightGraphsDFG, variable::DFGVariable)::DFGVariable = deleteVariable!(dfg, variable.label)
200200

201201
"""
202202
$(SIGNATURES)
@@ -476,7 +476,7 @@ Get a deep subgraph copy from the DFG given a list of variables and factors.
476476
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
477477
Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
478478
"""
479-
function getSubgraph(dfg::LightGraphsDFG, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false, addToDFG::LightGraphsDFG=LightGraphsDFG())::LightGraphsDFG
479+
function getSubgraph(dfg::LightGraphsDFG, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false, addToDFG::LightGraphsDFG=LightGraphsDFG{AbstractParams}())::LightGraphsDFG
480480
for label in variableFactorLabels
481481
if !haskey(dfg.g.metaindex[:label], label)
482482
error("Variable/factor with label '$(label)' does not exist in the factor graph")

test/interfaceTests.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ dfg = testDFGAPI{NoSolverParams}()
22
v1 = DFGVariable(:a)
33
v2 = DFGVariable(:b)
44
f1 = DFGFactor{Int, :Symbol}(:f1)
5+
6+
#add tags for filters
7+
append!(v1.tags,[:VARIABLE, :POSE])
8+
append!(v2.tags, [:VARIABLE, :LANDMARK])
9+
append!(f1.tags, [:FACTOR])
10+
511
# @testset "Creating Graphs" begin
612
global dfg,v1,v2,f1
713
addVariable!(dfg, v1)
@@ -10,12 +16,40 @@ addFactor!(dfg, [v1, v2], f1)
1016
@test_throws Exception addFactor!(dfg, DFGFactor{Int, :Symbol}("f2"), [v1, DFGVariable("Nope")])
1117
# end
1218

19+
@testset "Adding Removing Nodes" begin
20+
dfg2 = testDFGAPI{NoSolverParams}()
21+
v1 = DFGVariable(:a)
22+
v2 = DFGVariable(:b)
23+
v3 = DFGVariable(:c)
24+
f1 = DFGFactor{Int, :Symbol}(:f1)
25+
f2 = DFGFactor{Int, :Symbol}(:f2)
26+
# @testset "Creating Graphs" begin
27+
@test addVariable!(dfg2, v1)
28+
@test addVariable!(dfg2, v2)
29+
@test_throws ErrorException updateVariable!(dfg2, v3)
30+
@test addVariable!(dfg2, v3)
31+
@test_throws ErrorException addVariable!(dfg2, v3)
32+
@test addFactor!(dfg2, [v1, v2], f1)
33+
@test_throws ErrorException addFactor!(dfg2, [v1, v2], f1)
34+
@test_throws ErrorException updateFactor!(dfg2, f2)
35+
@test addFactor!(dfg2, [:b, :c], f2)
36+
@test deleteVariable!(dfg2, v3) == v3
37+
@test symdiff(ls(dfg2),[:a,:b]) == []
38+
@test deleteFactor!(dfg2, f2) == f2
39+
@test lsf(dfg2) == [:f1]
40+
end
41+
1342
@testset "Listing Nodes" begin
1443
global dfg,v1,v2,f1
1544
@test length(ls(dfg)) == 2
1645
@test length(lsf(dfg)) == 1
1746
@test symdiff([:a, :b], getVariableIds(dfg)) == []
1847
@test getFactorIds(dfg) == [:f1]
48+
#
49+
@test lsf(dfg, :a) == [f1.label]
50+
#tags
51+
@test ls(dfg, tags=[:POSE]) == [:a]
52+
@test symdiff(ls(dfg, tags=[:POSE, :LANDMARK]), ls(dfg, tags=[:VARIABLE])) == []
1953
# Regexes
2054
@test ls(dfg, r"a") == [v1.label]
2155
@test lsf(dfg, r"f*") == [f1.label]
@@ -137,6 +171,10 @@ end
137171
# Test adding to the dfg
138172
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 2, true, dfgSubgraph)
139173
@test symdiff([:x1, :x1x2f1, :x2], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
174+
#
175+
dfgSubgraph = getSubgraph(dfg,[:x1, :x2, :x1x2f1])
176+
# Only returns x1 and x2
177+
@test symdiff([:x1, :x1x2f1, :x2], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
140178
end
141179

142180
@testset "Producing Dot Files" begin

0 commit comments

Comments
 (0)