Skip to content

Commit ba0d059

Browse files
authored
Merge pull request #416 from JuliaRobotics/maint/20Q2/cgtests
Update cgdfg tests and small bugfixes
2 parents 6a37212 + 4865411 commit ba0d059

File tree

3 files changed

+94
-42
lines changed

3 files changed

+94
-42
lines changed

src/services/AbstractDFG.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,16 @@ function deepcopyGraph(::Type{T},
877877
sourceDFG::AbstractDFG,
878878
variableLabels::Vector{Symbol} = ls(sourceDFG),
879879
factorLabels::Vector{Symbol} = lsf(sourceDFG);
880+
sessionId::String = "",
880881
kwargs...) where T <: AbstractDFG
881-
destDFG = T(getDFGInfo(sourceDFG)...)
882+
883+
ginfo = [getDFGInfo(sourceDFG)...]
884+
if sessionId == ""
885+
ginfo[4] *= "_copy$(string(uuid4())[1:6])"
886+
else
887+
ginfo[4] = sessionId
888+
end
889+
destDFG = T(ginfo...)
882890
copyGraph!(destDFG, sourceDFG, variableLabels, factorLabels; deepcopyNodes=true, kwargs...)
883891
return destDFG
884892
end

test/consolInterfaceDev.jl

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using Neo4j
44
using DistributedFactorGraphs
55
using Pkg
66
using Dates
7-
7+
using UUIDs
88
# using IncrementalInference
99

1010
include("testBlocks.jl")
@@ -15,14 +15,20 @@ testDFGAPI = CloudGraphsDFG
1515
# TODO maybe move to cloud graphs permanantly as standard easy to use functions
1616
function DFG.CloudGraphsDFG(; params=NoSolverParams())
1717
cgfg = CloudGraphsDFG{typeof(params)}("localhost", 7474, "neo4j", "test",
18-
"testUser", "testRobot", "testSession",
18+
"testUser", "testRobot", "testSession_$(string(uuid4())[1:6])",
1919
"description",
2020
nothing,
2121
nothing,
22-
(dfg,f)->f,#IncrementalInference.decodePackedType,#(dfg,f)->f,
23-
(dfg,f)->f,#ncrementalInference.rebuildFactorMetadata!,#(dfg,f)->f,
22+
(dfg,f)->f,#IncrementalInference.decodePackedType,
23+
(dfg,f)->f,#ncrementalInference.rebuildFactorMetadata!,
2424
solverParams=params)
2525
createDfgSessionIfNotExist(cgfg)
26+
27+
setUserData!(cgfg, Dict{Symbol, String}())
28+
setRobotData!(cgfg, Dict{Symbol, String}())
29+
setSessionData!(cgfg, Dict{Symbol, String}())
30+
setDescription!(cgfg, cgfg.description)
31+
2632
return cgfg
2733
end
2834

@@ -49,8 +55,8 @@ function DFG.CloudGraphsDFG(description::String,
4955
description,
5056
nothing,
5157
nothing,
52-
(dfg,f)->f,#IncrementalInference.decodePackedType,#(dfg,f)->f,
53-
(dfg,f)->f,#IncrementalInference.rebuildFactorMetadata!,#(dfg,f)->f,
58+
(dfg,f)->f,#IncrementalInference.decodePackedType,
59+
(dfg,f)->f,#IncrementalInference.rebuildFactorMetadata!,
5460
solverParams=solverParams)
5561

5662
createDfgSessionIfNotExist(cdfg)
@@ -119,7 +125,7 @@ end
119125

120126
@testset "Adjacency Matrices" begin
121127
fg = testDFGAPI()
122-
clearRobot!!(fg)
128+
clearUser!!(fg)
123129

124130
DFGVariable(:a, TestSofttype1())
125131
addVariable!(fg, var1)
@@ -133,38 +139,69 @@ end
133139

134140

135141
@testset "Getting Neighbors" begin
142+
fg = testDFGAPI()
143+
clearUser!!(fg)
136144
GettingNeighbors(testDFGAPI)
137145
end
138146

139147

140148
@testset "Getting Subgraphs" begin
149+
fg = testDFGAPI()
150+
clearUser!!(fg)
141151
GettingSubgraphs(testDFGAPI)
142152
end
143153

144-
# @testset "Building Subgraphs" begin
145-
# BuildingSubgraphs(testDFGAPI)
146-
# end
154+
@testset "Building Subgraphs" begin
155+
fg = testDFGAPI()
156+
clearUser!!(fg)
157+
BuildingSubgraphs(testDFGAPI)
158+
end
147159
#
148160
# #TODO Summaries and Summary Graphs
149-
# @testset "Summaries and Summary Graphs" begin
150-
# Summaries(testDFGAPI)
151-
# end
152-
#
153-
# @testset "Producing Dot Files" begin
154-
# ProducingDotFiles(testDFGAPI)
155-
# end
161+
@testset "Summaries and Summary Graphs" begin
162+
Summaries(testDFGAPI)
163+
end
164+
165+
@testset "Producing Dot Files" begin
166+
fg = testDFGAPI()
167+
clearUser!!(fg)
168+
ProducingDotFiles(testDFGAPI, var1, var2, fac1)
169+
end
156170
#
157-
# @testset "Connectivity Test" begin
158-
# ConnectivityTest(testDFGAPI)
159-
# end
171+
@testset "Connectivity Test" begin
172+
fg = testDFGAPI()
173+
clearUser!!(fg)
174+
ConnectivityTest(testDFGAPI)
175+
end
176+
177+
@testset "Copy Functions" begin
178+
fg = testDFGAPI()
179+
clearUser!!(fg)
180+
fg = testDFGAPI()
181+
addVariable!(fg, var1)
182+
addVariable!(fg, var2)
183+
addVariable!(fg, var3)
184+
addFactor!(fg, fac1)
160185

186+
fgcopy = testDFGAPI()
187+
DFG._copyIntoGraph!(fg, fgcopy, union(ls(fg), lsf(fg)))
188+
@test getVariableOrder(fg,:abf1) == getVariableOrder(fgcopy,:abf1)
161189

190+
#test copyGraph, deepcopyGraph[!]
191+
fgcopy = testDFGAPI()
192+
DFG.deepcopyGraph!(fgcopy, fg)
193+
@test getVariableOrder(fg,:abf1) == getVariableOrder(fgcopy,:abf1)
194+
195+
CopyFunctionsTest(testDFGAPI)
196+
197+
end
162198
#
163-
#
164-
# fg = fg1
165-
# v1 = var1
166-
# v2 = var2
167-
# v3 = var3
168-
# f0 = fac0
169-
# f1 = fac1
170-
# f2 = fac2
199+
#=
200+
fg = fg1
201+
v1 = var1
202+
v2 = var2
203+
v3 = var3
204+
f0 = fac0
205+
f1 = fac1
206+
f2 = fac2
207+
=#

test/testBlocks.jl

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,10 @@ function testGroup!(fg, v1, v2, f0, f1)
820820
@test_skip varNearTs[1][1] == [:b]
821821

822822
## SORT copied from CRUD
823-
@test all(getVariables(fg, r"a") .== [v1])
824-
@test all(getVariables(fg, solvable=1) .== [v2])
823+
@test all(getVariables(fg, r"a") .== [getVariable(fg,v1.label)])
824+
@test all(getVariables(fg, solvable=1) .== [getVariable(fg,v2.label)])
825825
@test getVariables(fg, r"a", solvable=1) == []
826-
@test getVariables(fg, tags=[:LANDMARK])[1] == v2
826+
@test getVariables(fg, tags=[:LANDMARK])[1] == getVariable(fg, v2.label)
827827

828828
@test getFactors(fg, r"nope") == []
829829
@test issetequal(getLabel.(getFactors(fg, solvable=1)), [:af1, :abf1])
@@ -980,8 +980,6 @@ function connectivityTestGraph(::Type{T}; VARTYPE=DFGVariable, FACTYPE=DFGFactor
980980

981981
dfg = T()
982982

983-
isa(dfg, CloudGraphsDFG) && clearUser!!(dfg)
984-
985983
vars = vcat(map(n -> VARTYPE(Symbol("x$n"), VariableNodeData{TestSofttype1}()), 1:numNodesType1),
986984
map(n -> VARTYPE(Symbol("x$(numNodesType1+n)"), VariableNodeData{TestSofttype2}()), 1:numNodesType2))
987985

@@ -1167,22 +1165,31 @@ function Summaries(testDFGAPI)
11671165
end
11681166
end
11691167

1170-
function ProducingDotFiles(testDFGAPI; VARTYPE=DFGVariable, FACTYPE=DFGFactor)
1168+
function ProducingDotFiles(testDFGAPI,
1169+
v1 = nothing,
1170+
v2 = nothing,
1171+
f1 = nothing;
1172+
VARTYPE=DFGVariable,
1173+
FACTYPE=DFGFactor)
11711174
# "Producing Dot Files"
11721175
# create a simpler graph for dot testing
11731176
dotdfg = testDFGAPI()
1174-
v1 = VARTYPE(:a, VariableNodeData{TestSofttype1}())
1175-
v2 = VARTYPE(:b, VariableNodeData{TestSofttype1}())
1176-
if FACTYPE==DFGFactor
1177-
f1 = DFGFactor{Int, :Symbol}(:abf1)
1178-
else
1179-
f1 = FACTYPE(:abf1)
1177+
1178+
if v1 == nothing
1179+
v1 = VARTYPE(:a, VariableNodeData{TestSofttype1}())
11801180
end
1181+
if v2 == nothing
1182+
v2 = VARTYPE(:b, VariableNodeData{TestSofttype1}())
1183+
end
1184+
if f1 == nothing
1185+
f1 = (FACTYPE==DFGFactor) ? DFGFactor{Int, :Symbol}(:abf1) : FACTYPE(:abf1)
1186+
end
1187+
11811188
addVariable!(dotdfg, v1)
11821189
addVariable!(dotdfg, v2)
11831190
addFactor!(dotdfg, [v1, v2], f1)
11841191
#NOTE hardcoded toDot will have different results so test LightGraphs seperately
1185-
if testDFGAPI <: LightDFG
1192+
if testDFGAPI <: LightDFG || testDFGAPI <: CloudGraphsDFG
11861193
@test toDot(dotdfg) == "graph G {\na [color=red, shape=ellipse];\nb [color=red, shape=ellipse];\nabf1 [color=blue, shape=box];\na -- abf1\nb -- abf1\n}\n"
11871194
else
11881195
@test toDot(dotdfg) == "graph graphname {\n2 [\"label\"=\"b\",\"shape\"=\"ellipse\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n2 -- 3\n3 [\"label\"=\"abf1\",\"shape\"=\"box\",\"fillcolor\"=\"blue\",\"color\"=\"blue\"]\n1 [\"label\"=\"a\",\"shape\"=\"ellipse\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n1 -- 3\n}\n"

0 commit comments

Comments
 (0)