Skip to content

Commit f6d7c32

Browse files
authored
Improved Tests (#277)
* Improve tags test and API * Lists tests
1 parent dbae574 commit f6d7c32

File tree

5 files changed

+161
-61
lines changed

5 files changed

+161
-61
lines changed
File renamed without changes.

src/Common.jl

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -114,34 +114,38 @@ Related
114114
ls, lsf
115115
"""
116116
sortDFG(vars::Vector{Symbol})::Vector{Symbol} = sortVarNested(vars)
117-
"""
118-
$SIGNATURES
119-
120-
Return the factor type used in a `::DFGFactor`.
121-
122-
Notes:
123-
- OBSOLETE, use newer getFactorType instead.
124-
125-
Related
126117

127-
getFactorType
128-
"""
129-
function getfnctype(data::GenericFunctionNodeData)
130-
# TODO what is this?
131-
if typeof(data).name.name == :VariableNodeData
132-
return VariableNodeData
133-
end
134-
135-
# this looks right
136-
return data.fnc.usrfnc!
137-
end
138-
function getfnctype(fact::DFGFactor; solveKey::Symbol=:default)
139-
data = getSolverData(fact) # TODO , solveKey=solveKey)
140-
return getfnctype(data)
141-
end
142-
function getfnctype(dfg::T, lbl::Symbol; solveKey::Symbol=:default) where T <: AbstractDFG
143-
getfnctype(getFactor(dfg, exvertid))
144-
end
118+
#TODO Is this deprecate in favor of getFactorType, or OBSOLETE?
119+
# """
120+
# $SIGNATURES
121+
#
122+
# Return the factor type used in a `::DFGFactor`.
123+
#
124+
# Notes:
125+
# - OBSOLETE, use newer getFactorType instead.
126+
#
127+
# Related
128+
#
129+
# getFactorType
130+
# """
131+
# function getfnctype(data::GenericFunctionNodeData)
132+
# # TODO what is this?
133+
# if typeof(data).name.name == :VariableNodeData
134+
# return VariableNodeData
135+
# end
136+
#
137+
# # this looks right
138+
# return data.fnc.usrfnc!
139+
# end
140+
# function getfnctype(fact::DFGFactor; solveKey::Symbol=:default)
141+
# data = getSolverData(fact) # TODO , solveKey=solveKey)
142+
# return getfnctype(data)
143+
# end
144+
# function getfnctype(dfg::T, lbl::Symbol; solveKey::Symbol=:default) where T <: AbstractDFG
145+
# getfnctype(getFactor(dfg, exvertid))
146+
# end
147+
148+
@deprecate getfnctype(args...) getFactorType(args...)
145149

146150
"""
147151
$SIGNATURES
@@ -190,9 +194,9 @@ end
190194
191195
Return the DFGVariable softtype in factor graph `dfg<:AbstractDFG` and label `::Symbol`.
192196
"""
193-
getVariableType(var::DFGVariable; solveKey::Symbol=:default) = getSofttype(var, solveKey=solveKey)
194-
function getVariableType(dfg::G, lbl::Symbol; solveKey::Symbol=:default) where G <: AbstractDFG
195-
getVariableType(getVariable(dfg, lbl), solveKey=solveKey)
197+
getVariableType(var::DFGVariable) = getSofttype(var)
198+
function getVariableType(dfg::G, lbl::Symbol) where G <: AbstractDFG
199+
getVariableType(getVariable(dfg, lbl))
196200
end
197201

198202

@@ -241,9 +245,9 @@ function lsTypes(dfg::G)::Dict{Symbol, Vector{String}} where G <: AbstractDFG
241245
end
242246

243247

244-
function ls(dfg::G, ::Type{T}; solveKey::Symbol=:default) where {G <: AbstractDFG, T <: InferenceVariable}
248+
function ls(dfg::G, ::Type{T}) where {G <: AbstractDFG, T <: InferenceVariable}
245249
xx = getVariables(dfg)
246-
mask = getVariableType.(xx, solveKey=solveKey) .|> typeof .== T
250+
mask = getVariableType.(xx) .|> typeof .== T
247251
vxx = view(xx, mask)
248252
map(x->x.label, vxx)
249253
end
@@ -274,11 +278,11 @@ Related
274278
275279
ls, lsf, lsfPriors
276280
"""
277-
function lsWho(dfg::AbstractDFG, type::Symbol; solveKey::Symbol=:default)::Vector{Symbol}
281+
function lsWho(dfg::AbstractDFG, type::Symbol)::Vector{Symbol}
278282
vars = getVariables(dfg)
279283
labels = Symbol[]
280284
for v in vars
281-
varType = typeof(getVariableType(v, solveKey=solveKey)).name |> Symbol
285+
varType = typeof(getVariableType(v)).name |> Symbol
282286
varType == type && push!(labels, v.label)
283287
end
284288
return labels
@@ -390,48 +394,56 @@ function findVariableNearTimestamp(dfg::AbstractDFG,
390394
return RET
391395
end
392396

397+
398+
#TAGS as a set, list, merge, remove, empty
393399
"""
394400
$SIGNATURES
395401
396402
Return the tags for a variable or factor.
397403
"""
398-
function getTags(dfg::InMemoryDFGTypes, sym::Symbol)
404+
function listTags(dfg::InMemoryDFGTypes, sym::Symbol)
399405
getFnc = isVariable(dfg,sym) ? getVariable : getFactor
400406
getTags(getFnc(dfg, sym))
401407
end
408+
#alias for completeness
409+
listTags(f::DataLevel0) = getTags(f)
402410

403411
"""
404412
$SIGNATURES
405413
406-
Add tags to a variable or factor
414+
Merge add tags to a variable or factor (union)
407415
"""
408-
function addTags!(dfg::InMemoryDFGTypes, sym::Symbol, tags::Vector{Symbol})
416+
function mergeTags!(dfg::InMemoryDFGTypes, sym::Symbol, tags::Vector{Symbol})
409417
getFnc = isVariable(dfg,sym) ? getVariable : getFactor
410418
union!(getTags(getFnc(dfg, sym)), tags)
411419
end
420+
mergeTags!(f::DataLevel0, tags::Vector{Symbol}) = union!(f.tags, tags)
412421

413422

414423
"""
415424
$SIGNATURES
416425
417-
Add tag to a variable or factor
426+
Remove the tags from the node (setdiff)
418427
"""
419-
addTag!(f::DataLevel0, tag::Symbol) = union!(f.tags,[tag])
420-
428+
function removeTags!(dfg::InMemoryDFGTypes, sym::Symbol, tags::Vector{Symbol})
429+
getFnc = isVariable(dfg,sym) ? getVariable : getFactor
430+
setdiff!(getTags(getFnc(dfg, sym)), tags)
431+
end
432+
removeTags!(f::DataLevel0, tags::Vector{Symbol}) = setdiff!(f.tags, tags)
421433

422434
"""
423435
$SIGNATURES
424436
425-
Merge tags to the node's tags (variable/factor).
437+
Empty all tags from the node (empty)
426438
"""
427-
mergeTags!(f::DataLevel0, tags::Vector{Symbol}) = union!(f.tags, tags)
439+
function emptyTags!(dfg::InMemoryDFGTypes, sym::Symbol)
440+
getFnc = isVariable(dfg,sym) ? getVariable : getFactor
441+
empty!(getTags(getFnc(dfg, sym)))
442+
end
443+
emptyTags!(f::DataLevel0) = empty!(f.tags)
444+
428445

429-
"""
430-
$SIGNATURES
431446

432-
Remove the tags from the node
433-
"""
434-
deleteTags!(f::DataLevel0, tags::Vector{Symbol}) = setdiff!(f.tags, tags)
435447

436448

437449
"""
@@ -444,7 +456,7 @@ function hasTags(dfg::InMemoryDFGTypes,
444456
tags::Vector{Symbol};
445457
matchAll::Bool=true )::Bool
446458
#
447-
alltags = getTags(dfg, sym)
459+
alltags = listTags(dfg, sym)
448460
length(filter(x->x in alltags, tags)) >= (matchAll ? length(tags) : 1)
449461
end
450462

src/DistributedFactorGraphs.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ export pack, unpack
8686
# Resolve with above
8787
export packVariable, unpackVariable, packFactor, unpackFactor
8888

89+
# TODO TAGS
90+
export listTags, mergeTags!, removeTags!, emptyTags!
8991
# PPE exports
9092
export AbstractPointParametricEst
9193
export MeanMaxPPE

test/iifInterfaceTests.jl

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ end
3030

3131
@testset "Testing CRUD, return and Failures from a GraphsDFG" begin
3232
global dfg
33-
# fg to copy to
33+
# dfg to copy to
3434
# creating a whole new graph with the same labels
3535
T = typeof(dfg)
3636
if T <: CloudGraphsDFG
@@ -124,6 +124,44 @@ end
124124
@test !isVariable(dfg, f1.label)
125125
@test !isVariable(dfg, :doesntexist)
126126
@test !isFactor(dfg, :doesntexist)
127+
128+
@test issetequal([:a,:b], listVariables(dfg))
129+
@test issetequal([:abf1], listFactors(dfg))
130+
131+
@test @test_deprecated getVariableIds(dfg) == listVariables(dfg)
132+
@test @test_deprecated getFactorIds(dfg) == listFactors(dfg)
133+
134+
135+
@test @test_deprecated getfnctype(f1.solverData) === getFactorType(f1.solverData)
136+
@test @test_deprecated getfnctype(f1) === getFactorType(f1)
137+
@test @test_deprecated getfnctype(dfg, :abf1) === getFactorType(dfg, :abf1)
138+
139+
@test getFactorType(f1.solverData) === f1.solverData.fnc.usrfnc!
140+
@test getFactorType(f1) === f1.solverData.fnc.usrfnc!
141+
@test getFactorType(dfg, :abf1) === f1.solverData.fnc.usrfnc!
142+
143+
@test !isPrior(dfg, :abf1) # f1 is not a prior
144+
@test lsfPriors(dfg) == []
145+
#FIXME don't know what it is supposed to do
146+
@test_broken lsfTypes(dfg)
147+
148+
@test ls(dfg, LinearConditional) == [:abf1]
149+
@test lsf(dfg, LinearConditional) == [:abf1]
150+
@test lsfWho(dfg, :LinearConditional) == [:abf1]
151+
152+
@test getVariableType(v1) isa ContinuousScalar
153+
@test getVariableType(dfg,:a) isa ContinuousScalar
154+
155+
#TODO what is lsTypes supposed to return?
156+
@test_broken lsTypes(dfg)
157+
158+
@test issetequal(ls(dfg, ContinuousScalar), [:a, :b])
159+
160+
@test issetequal(lsWho(dfg, :ContinuousScalar),[:a, :b])
161+
162+
varNearTs = findVariableNearTimestamp(dfg, now())
163+
@test_skip varNearTs[1][1] == [:b]
164+
127165
end
128166

129167
# Gets
@@ -346,7 +384,7 @@ end
346384

347385
# Now make a complex graph for connectivity tests
348386
numNodes = 10
349-
#the deletions in last test should have cleared out the fg
387+
#the deletions in last test should have cleared out the dfg
350388
# dfg = DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg)
351389
# if typeof(dfg) <: CloudGraphsDFG
352390
# clearSession!!(dfg)

test/interfaceTests.jl

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,55 @@ end
332332
end
333333

334334

335-
##
336335
@testset "TODO Sorteer groep" begin
337336

337+
@testset "Listing Variables and Factors with filters" begin
338+
339+
@test issetequal([:a,:b], listVariables(fg))
340+
@test issetequal([:f1], listFactors(fg))
341+
342+
@test @test_deprecated getVariableIds(fg) == listVariables(fg)
343+
@test @test_deprecated getFactorIds(fg) == listFactors(fg)
344+
345+
# TODO Mabye implement IIF type here
346+
# Requires IIF or a type in IIF
347+
@test_skip @test_deprecated getfnctype(f1.solverData) === getFactorType(f1.solverData)
348+
@test_skip @test_deprecated getfnctype(f1) === getFactorType(f1)
349+
@test_skip @test_deprecated getfnctype(fg, :f1) === getFactorType(fg, :f1)
350+
@test_broken getFactorType(f1.solverData) === f1.solverData.fnc.usrfnc!
351+
@test_broken getFactorType(f1) === f1.solverData.fnc.usrfnc!
352+
@test_broken getFactorType(fg, :f1) === f1.solverData.fnc.usrfnc!
353+
354+
@test_broken isPrior(fg, :f1) # if f1 is prior
355+
@test_broken lsfPriors(fg) == [:f1]
356+
@test_broken lsfTypes(fg)
357+
358+
@test_broken ls(fg, TestFunctorInferenceType1) == [f1]
359+
@test_broken lsf(fg, TestFunctorInferenceType1) == [f1]
360+
@test_broken lsfWho(fg, :TestFunctorInferenceType1) == [f1]
361+
362+
@test getVariableType(v1) == TestInferenceVariable1()
363+
@test getVariableType(fg,:a) == TestInferenceVariable1()
364+
365+
#TODO what is lsTypes supposed to return?
366+
lsTypes(fg)
367+
368+
@test ls(fg, TestInferenceVariable1) == [:a]
369+
370+
@test lsWho(fg, :TestInferenceVariable1) == [:a]
371+
372+
varNearTs = findVariableNearTimestamp(fg, now())
373+
@test varNearTs[1][1] == [:b]
374+
375+
#TODO test filters and options
376+
# regexFilter::Union{Nothing, Regex}=nothing;
377+
# tags::Vector{Symbol}=Symbol[],
378+
# solvable::Int=0,
379+
# warnDuplicate::Bool=true,
380+
# number::Int=1
381+
382+
end
383+
338384
@testset "Connectivity Test" begin
339385

340386
if testDFGAPI == GraphsDFG
@@ -397,22 +443,24 @@ end
397443
@test sort(l, lt=DistributedFactorGraphs.natural_lt) == [Symbol("1a1"), :X1, :a, :a1, :b1c2, :c, :l1, :x1, :x1_1, :x1_2, :x1l1f1, :x1x2f1, :x2_1, :x2_2, :x10, :x10_10, :xy3]
398444
end
399445
end
400-
#
446+
401447
@testset "tags" begin
402448
#
403-
# LOTS TODO
404449

405-
@test issetequal(getTags(fg, :a), v1_tags)
450+
v1Tags = deepcopy(getTags(v1))
451+
@test issetequal(v1Tags, v1_tags)
452+
@test issetequal(listTags(fg, :a), v1Tags)
453+
@test issetequal(mergeTags!(fg, :a, [:TAG]), v1Tags [:TAG])
454+
@test issetequal(removeTags!(fg, :a, [:TAG]), v1Tags)
455+
@test emptyTags!(fg, :a) == Set{Symbol}()
406456

407-
# TODO do we error on duplicates
408-
@test issetequal(addTags!(fg, :a, [:TAG]), v1_tags [:TAG])
409457

410-
@test_broken emptyTags!(fg, :a)
458+
v2Tags = [listTags(fg, :b)...]
459+
@test hasTags(fg, :b, [v2Tags...])
460+
@test hasTags(fg, :b, [:LANDMARK, :TAG], matchAll=false)
411461

412-
@test_broken updateTags!
413-
@test_broken deleteTags!
414-
@test_broken listTags
415-
@test_broken mergeTags!
462+
@test hasTagsNeighbors(fg, :f1, [:LANDMARK])
463+
@test !hasTagsNeighbors(fg, :f1, [:LANDMARK, :TAG])
416464

417465
end
418466

0 commit comments

Comments
 (0)