-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFactorGraphsTests.jl
84 lines (64 loc) · 2.3 KB
/
FactorGraphsTests.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using Test
using DistributedFactorGraphs
using DistributedFactorGraphs.GraphsDFGs.FactorGraphs
@testset "GraphsDFGs.FactorGraphs BiMaps" begin
@test isa(FactorGraphs.BiDictMap(), FactorGraphs.BiDictMap{Int64})
bi = FactorGraphs.BiDictMap{Int}()
@test (bi[1] = :x1) == :x1
@test bi[:x1] == 1
@test (bi[2] = :x1) == :x1
@test bi[:x1] == 2
@test_throws KeyError bi[1]
@test haskey(bi, 2)
@test !haskey(bi, 1)
@test haskey(bi, :x1)
@test !haskey(bi, :x10)
@test (bi[:x10] = 10) == 10
@test bi[10] == :x10
@test (bi[:x11] = 10) == 10
@test !haskey(bi, :x10)
bi[1] = :x1
bi[:x1] = 2
bi[3] = :x1
bi[4] = :x2
bi[:x3] = 4
@test length(bi.sym_int) == 3
@test length(bi.int_sym) == 3
@test length(bi) == 3
@test !(isempty(bi))
end
@testset "GraphsDFGs.FactorGraphs" begin
@test isa(
FactorGraphs.FactorGraph(),
FactorGraph{Int64, AbstractDFGVariable, AbstractDFGFactor},
)
fg = FactorGraphs.FactorGraph{Int, VariableSkeleton, FactorSkeleton}()
@test !FactorGraphs.is_directed(fg)
@test !FactorGraphs.is_directed(FactorGraph{Int, VariableSkeleton, FactorSkeleton})
@test isa(zero(fg), FactorGraph{Int64, VariableSkeleton, FactorSkeleton})
# @test
@test FactorGraphs.addVariable!(fg, VariableSkeleton(:a))
@test @test_logs (:error, r"already") !FactorGraphs.addVariable!(
fg,
VariableSkeleton(:a),
)
@test FactorGraphs.addVariable!(fg, VariableSkeleton(:b))
@test FactorGraphs.addFactor!(fg, [:a, :b], FactorSkeleton(:abf1, [:a, :b]))
@test @test_logs (:error, r"already") !FactorGraphs.addFactor!(
fg,
[:a, :b],
FactorSkeleton(:abf1, [:a, :b]),
)
@test_throws KeyError FactorGraphs.addFactor!(
fg,
[:a, :c],
FactorSkeleton(:acf1, [:a, :c]),
)
@test eltype(fg) == Int
@test FactorGraphs.edgetype(fg) == FactorGraphs.Graphs.SimpleGraphs.SimpleEdge{Int64}
@test FactorGraphs.has_vertex(fg, 1)
@test !FactorGraphs.has_vertex(fg, 4)
@test FactorGraphs.has_edge(fg, FactorGraphs.Graphs.SimpleGraphs.SimpleEdge(1, 3))
@test FactorGraphs.rem_edge!(fg, FactorGraphs.Graphs.SimpleGraphs.SimpleEdge(2, 3))
@test !FactorGraphs.has_edge(fg, FactorGraphs.Graphs.SimpleGraphs.SimpleEdge(2, 3))
end