Skip to content

Commit 53e7a37

Browse files
committed
Test improvement:
* LightGraphs.FactorGraphs * test compare NodeData * interface not implemented
1 parent 04240cc commit 53e7a37

File tree

6 files changed

+126
-21
lines changed

6 files changed

+126
-21
lines changed

src/LightDFG/FactorGraphs/BiMaps.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Base.haskey(b::BiDictMap, s::Symbol) = haskey(b.sym_int, s)
4646
Base.haskey(b::BiDictMap, i::Int) = haskey(b.int_sym, i)
4747

4848
Base.length(b::BiDictMap) = length(b.int_sym)
49+
#NOTE to future self: This will work only with LightGraphs that always follows a 1:nv(g) index
4950
Base.firstindex(v::BiDictMap) = 1
5051
Base.lastindex(v::BiDictMap) = length(v.int_sym)
5152
Base.iterate(v::BiDictMap, i=1) = (length(v.int_sym) < i ? nothing : (v.int_sym[i], i + 1))

src/LightDFG/FactorGraphs/FactorGraphs.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ import LightGraphs.SimpleGraphs:
2323
SimpleEdge, fadj, badj
2424

2525
export
26-
FactorGraph,
26+
FactorGraph
2727
# addVariable!,
2828
# addFactor!,
29-
LightBayesGraph,
30-
filter_edges,
31-
filter_vertices,
32-
reverse
29+
# LightBayesGraph,
30+
# filter_edges,
31+
# filter_vertices,
32+
# reverse
3333

3434
# import DistributedFactorGraphs: DFGNode
3535
# const AbstractNodeType = DFGNode
@@ -61,7 +61,7 @@ end
6161
# fg = FactorGraph{Int, AbstractVariableType, AbstractFactorType}()
6262

6363
FactorGraph() = FactorGraph{Int, AbstractVariableType, AbstractFactorType}()
64-
FactorGraph{V,F}() where {V <: AbstractVariableType, F <: AbstractFactorType} = FactorGraph{Int, V, F}()
64+
# FactorGraph{V,F}() where {V <: AbstractVariableType, F <: AbstractFactorType} = FactorGraph{Int, V, F}()
6565

6666

6767
function show(io::IO, g::FactorGraph)

src/services/CompareUtils.jl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,3 @@ function compareFactorGraphs(fgA::G1,
387387

388388
return TP
389389
end
390-
391-
392-
# """
393-
# ==(x::T, y::T) where T <: AbstractPointParametricEst
394-
# Equality check for AbstractPointParametricEst.
395-
# """
396-
# @generated function ==(x::T, y::T) where T <: AbstractPointParametricEst
397-
# mapreduce(n -> :(x.$n == y.$n), (a,b)->:($a && $b), fieldnames(x))
398-
# end
399-
#
400-
# @generated function Base.:(==)(x::T, y::T) where T <: Union{DFGFactorSummary, DFGVariableSummary, SkeletonDFGVariable, SkeletonDFGFactor}
401-
# mapreduce(n -> :(x.$n == y.$n), (a,b)->:($a && $b), fieldnames(x))
402-
# end

test/LightFactorGraphsTests.jl

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using Test
2+
using DistributedFactorGraphs
3+
4+
using DistributedFactorGraphs.LightDFGs.FactorGraphs
5+
6+
7+
@testset "LightDFGs.FactorGraphs BiMaps" begin
8+
9+
@test isa(FactorGraphs.BiDictMap(), FactorGraphs.BiDictMap{Int64})
10+
bi = FactorGraphs.BiDictMap{Int}()
11+
12+
@test (bi[1] = :x1) == :x1
13+
@test bi[:x1] == 1
14+
@test (bi[2] = :x1) == :x1
15+
@test bi[:x1] == 2
16+
@test_throws KeyError bi[1]
17+
18+
@test haskey(bi,2)
19+
@test !haskey(bi,1)
20+
@test haskey(bi,:x1)
21+
@test !haskey(bi,:x10)
22+
23+
@test (bi[:x10] = 10) == 10
24+
@test bi[10] == :x10
25+
26+
@test (bi[:x11] = 10) == 10
27+
28+
@test !haskey(bi,:x10)
29+
30+
bi[1] = :x1
31+
bi[:x1] = 2
32+
bi[3] = :x1
33+
bi[4] = :x2
34+
bi[:x3] = 4
35+
36+
@test length(bi.sym_int) == 3
37+
@test length(bi.int_sym) == 3
38+
@test length(bi) == 3
39+
@test !(isempty(bi))
40+
41+
end
42+
43+
@testset "LightDFGs.FactorGraphs" begin
44+
45+
46+
@test isa(FactorGraph(), FactorGraph{Int64,AbstractDFGVariable,AbstractDFGFactor})
47+
48+
fg = FactorGraph{Int, SkeletonDFGVariable, SkeletonDFGFactor}()
49+
50+
@test !FactorGraphs.is_directed(fg)
51+
@test !FactorGraphs.is_directed(FactorGraph{Int, SkeletonDFGVariable, SkeletonDFGFactor})
52+
53+
@test isa(zero(fg), FactorGraph{Int64, SkeletonDFGVariable, SkeletonDFGFactor})
54+
55+
# @test
56+
@test FactorGraphs.addVariable!(fg, SkeletonDFGVariable(:a))
57+
@test @test_logs (:error, r"already") !FactorGraphs.addVariable!(fg, SkeletonDFGVariable(:a))
58+
@test FactorGraphs.addVariable!(fg, SkeletonDFGVariable(:b))
59+
60+
@test FactorGraphs.addFactor!(fg, [:a,:b], SkeletonDFGFactor(:abf1, [:a,:b]))
61+
@test @test_logs (:error, r"already") !FactorGraphs.addFactor!(fg, [:a,:b], SkeletonDFGFactor(:abf1, [:a,:b]))
62+
@test @test_logs (:error, r"not found") !FactorGraphs.addFactor!(fg, [:a,:c], SkeletonDFGFactor(:acf1, [:a,:c]))
63+
64+
@test eltype(fg) == Int
65+
66+
@test FactorGraphs.edgetype(fg) == FactorGraphs.LightGraphs.SimpleGraphs.SimpleEdge{Int64}
67+
68+
@test FactorGraphs.has_vertex(fg, 1)
69+
@test !FactorGraphs.has_vertex(fg, 4)
70+
71+
@test FactorGraphs.has_edge(fg, FactorGraphs.LightGraphs.SimpleGraphs.SimpleEdge(1,3))
72+
73+
@test FactorGraphs.rem_edge!(fg, FactorGraphs.LightGraphs.SimpleGraphs.SimpleEdge(2,3))
74+
@test !FactorGraphs.has_edge(fg, FactorGraphs.LightGraphs.SimpleGraphs.SimpleEdge(2,3))
75+
76+
77+
end

test/compareTests.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ using Test
22
using DistributedFactorGraphs
33
using Dates
44

5+
#TODO implement with tests on
6+
# TestFunctorInferenceType1
7+
# TestCCW1
8+
9+
## Generated compare functions
510
# VariableNodeData
611
vnd1 = VariableNodeData(TestSofttype1())
712
vnd2 = deepcopy(vnd1)
@@ -59,3 +64,29 @@ f2.solverData = gfnd1
5964
f2.solverData = gfnd2
6065
@test !(f1 == f2)
6166
@test !(f1 == f3)
67+
68+
69+
## Compare functions
70+
vnd1 = VariableNodeData(TestSofttype1())
71+
vnd2 = deepcopy(vnd1)
72+
vnd3 = VariableNodeData(TestSofttype2())
73+
@test compare(vnd1, vnd2)
74+
@test !compare(vnd1, vnd3)
75+
76+
@test compare(vnd1, vnd2)
77+
vnd2.val = zeros(1,1)
78+
@test compare(vnd1, vnd2)
79+
vnd2.val[1] = 0.1
80+
@test !compare(vnd1, vnd2)
81+
@test !compare(vnd1, vnd3)
82+
83+
gfnd1 = GenericFunctionNodeData([:a,:b], true, true, [1,2], :symbol, sin)
84+
gfnd2 = deepcopy(gfnd1)
85+
gfnd3 = GenericFunctionNodeData([:a,:b], true, true, [1,2], :symbol, cos)
86+
87+
@test compare(gfnd1, gfnd2)
88+
gfnd2.fncargvID = [:a, :b]
89+
@test compare(gfnd1, gfnd2)
90+
gfnd2.fncargvID = [:b, :a]
91+
@test !(compare(gfnd1, gfnd2))
92+
@test_broken !(compare(gfnd1, gfnd3))

test/runtests.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,11 @@ else
140140
@warn "Skipping IncrementalInference driver tests"
141141
end
142142

143-
struct NotImplementedDFG <: AbstractDFG end
143+
@testset "Testing LightDFG.FactorGraphs functions" begin
144+
include("LightFactorGraphsTests.jl")
145+
end
144146

147+
struct NotImplementedDFG <: AbstractDFG end
145148

146149
@testset "No Interface tests" begin
147150
dfg = NotImplementedDFG()
@@ -167,5 +170,11 @@ struct NotImplementedDFG <: AbstractDFG end
167170
@test_throws ErrorException getFactors(dfg)
168171
@test_throws ErrorException isFullyConnected(dfg)
169172
@test_throws ErrorException getNeighbors(dfg, v1)
170-
@test_throws ErrorException getNeighbors(dfg, v1)
173+
@test_throws ErrorException getNeighbors(dfg, :a)
174+
175+
@test_throws ErrorException _getDuplicatedEmptyDFG(dfg)
176+
177+
@test_throws ErrorException isVariable(dfg, :a)
178+
@test_throws ErrorException isFactor(dfg, :a)
179+
171180
end

0 commit comments

Comments
 (0)