Skip to content

Commit 7a06fbe

Browse files
authored
Merge pull request #6 from JuliaRobotics/feature/testharness
Feature/testharness
2 parents f8694f4 + 0eb14b1 commit 7a06fbe

File tree

2 files changed

+107
-99
lines changed

2 files changed

+107
-99
lines changed

test/interfaceTests.jl

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
dfg = testDFGAPI()
2+
v1 = DFGVariable(:a)
3+
v2 = DFGVariable(:b)
4+
f1 = DFGFactor(:f1)
5+
@testset "Creating Graphs" begin
6+
global dfg,v1,v2,f1
7+
addVariable!(dfg, v1)
8+
@test_throws Exception addVariable!(dfg, v1)
9+
addVariable!(dfg, v2)
10+
addFactor!(dfg, f1, [v1, v2])
11+
@test_throws Exception addFactor!(dfg, DFGFactor("f2"), [v1, DFGVariable("Nope")])
12+
end
13+
14+
@testset "Listing Nodes" begin
15+
global dfg,v1,v2,f1
16+
@test length(ls(dfg)) == 2
17+
@test length(lsf(dfg)) == 1
18+
# Regexes
19+
@test ls(dfg, r"a") == [v1]
20+
@test lsf(dfg, r"f*") == [f1]
21+
end
22+
23+
# Gets
24+
@testset "Gets and Sets" begin
25+
global dfg,v1,v2,f1
26+
@test getVariable(dfg, v1.label) == v1
27+
@test getFactor(dfg, f1.label) == f1
28+
@test_throws Exception getVariable(dfg, :nope)
29+
@test_throws Exception getVariable(dfg, "nope")
30+
@test_throws Exception getFactor(dfg, :nope)
31+
@test_throws Exception getFactor(dfg, "nope")
32+
33+
# Sets
34+
v1Prime = deepcopy(v1)
35+
@test updateVariable!(dfg, v1Prime) != v1
36+
f1Prime = deepcopy(f1)
37+
@test updateFactor!(dfg, f1Prime) != f1
38+
end
39+
40+
# Deletions
41+
# Not supported at present
42+
@testset "Deletions" begin
43+
@warn "Deletions with Graph.jl is not supported at present"
44+
end
45+
46+
# Connectivity test
47+
@testset "Connectivity Test" begin
48+
global dfg,v1,v2,f1
49+
@test isFullyConnected(dfg) == true
50+
@test hasOrphans(dfg) == false
51+
addVariable!(dfg, DFGVariable(:orphan))
52+
@test isFullyConnected(dfg) == false
53+
@test hasOrphans(dfg) == true
54+
end
55+
56+
# Adjacency matrices
57+
@testset "Adjacency Matrices" begin
58+
global dfg,v1,v2,f1
59+
# Normal
60+
adjMat = getAdjacencyMatrix(dfg)
61+
@test size(adjMat) == (2,4)
62+
@test adjMat[1, :] == [nothing, :a, :b, :orphan]
63+
@test adjMat[2, :] == [:f1, :f1, :f1, nothing]
64+
# Dataframe
65+
adjDf = getAdjacencyMatrixDataFrame(dfg)
66+
@test size(adjDf) == (1,4)
67+
end
68+
69+
# Now make a complex graph for connectivity tests
70+
numNodes = 10
71+
dfg = testDFGAPI()
72+
verts = map(n -> DFGVariable(Symbol("x$n")), 1:numNodes)
73+
map(v -> addVariable!(dfg, v), verts)
74+
map(n -> addFactor!(dfg, DFGFactor(Symbol("x$(n)x$(n+1)f1")), [verts[n], verts[n+1]]), 1:(numNodes-1))
75+
# map(n -> addFactor!(dfg, [verts[n], verts[n+2]], DFGFactor(Symbol("x$(n)x$(n+2)f2"))), 1:2:(numNodes-2))
76+
77+
@testset "Getting Neighbors" begin
78+
global dfg,verts
79+
# Get neighbors tests
80+
@test getNeighbors(dfg, verts[1]) == [:x1x2f1]
81+
neighbors = getNeighbors(dfg, getFactor(dfg, :x1x2f1))
82+
@test all([v in [:x1, :x2] for v in neighbors])
83+
# Testing aliases
84+
@test getNeighbors(dfg, getFactor(dfg, :x1x2f1)) == ls(dfg, getFactor(dfg, :x1x2f1))
85+
@test getNeighbors(dfg, :x1x2f1) == ls(dfg, :x1x2f1)
86+
end
87+
88+
@testset "Getting Subgraphs" begin
89+
# Subgraphs
90+
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 2)
91+
# Only returns x1 and x2
92+
@test setdiff([:x1, :x1x2f1, :x2], map(n -> n.label, [ls(dfgSubgraph)..., lsf(dfgSubgraph)...])) == []
93+
# Test include orphan factorsVoid
94+
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 1, true)
95+
@test setdiff([:x1, :x1x2f1], map(n -> n.label, [ls(dfgSubgraph)..., lsf(dfgSubgraph)...])) == []
96+
# Test adding to the dfg
97+
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 2, true, dfgSubgraph)
98+
@test setdiff([:x1, :x1x2f1, :x2], map(n -> n.label, [ls(dfgSubgraph)..., lsf(dfgSubgraph)...])) == []
99+
end

test/runtests.jl

Lines changed: 8 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -3,102 +3,11 @@ using DataFrames
33
using DistributedFactorGraphs
44
using DistributedFactorGraphs.GraphsJl
55

6-
dfg = GraphsDFG()
7-
v1 = DFGVariable(:a)
8-
v2 = DFGVariable(:b)
9-
f1 = DFGFactor(:f1)
10-
@testset "Creating Graphs" begin
11-
global dfg,v1,v2,f1
12-
addVariable!(dfg, v1)
13-
@test_throws Exception addVariable!(dfg, v1)
14-
addVariable!(dfg, v2)
15-
addFactor!(dfg, f1, [v1, v2])
16-
@test_throws Exception addFactor!(dfg, DFGFactor("f2"), [v1, DFGVariable("Nope")])
17-
end
18-
19-
@testset "Listing Nodes" begin
20-
global dfg,v1,v2,f1
21-
@test length(ls(dfg)) == 2
22-
@test length(lsf(dfg)) == 1
23-
# Regexes
24-
@test ls(dfg, r"a") == [v1]
25-
@test lsf(dfg, r"f*") == [f1]
26-
end
27-
28-
# Gets
29-
@testset "Gets and Sets" begin
30-
global dfg,v1,v2,f1
31-
@test getVariable(dfg, v1.label) == v1
32-
@test getFactor(dfg, f1.label) == f1
33-
@test_throws Exception getVariable(dfg, :nope)
34-
@test_throws Exception getVariable(dfg, "nope")
35-
@test_throws Exception getFactor(dfg, :nope)
36-
@test_throws Exception getFactor(dfg, "nope")
37-
38-
# Sets
39-
v1Prime = deepcopy(v1)
40-
@test updateVariable!(dfg, v1Prime) != v1
41-
f1Prime = deepcopy(f1)
42-
@test updateFactor!(dfg, f1Prime) != f1
43-
end
44-
45-
# Deletions
46-
# Not supported at present
47-
@testset "Deletions" begin
48-
@warn "Deletions with Graph.jl is not supported at present"
49-
end
50-
51-
# Connectivity test
52-
@testset "Connectivity Test" begin
53-
global dfg,v1,v2,f1
54-
@test isFullyConnected(dfg) == true
55-
@test hasOrphans(dfg) == false
56-
addVariable!(dfg, DFGVariable(:orphan))
57-
@test isFullyConnected(dfg) == false
58-
@test hasOrphans(dfg) == true
59-
end
60-
61-
# Adjacency matrices
62-
@testset "Adjacency Matrices" begin
63-
global dfg,v1,v2,f1
64-
# Normal
65-
adjMat = getAdjacencyMatrix(dfg)
66-
@test size(adjMat) == (2,4)
67-
@test adjMat[1, :] == [nothing, :a, :b, :orphan]
68-
@test adjMat[2, :] == [:f1, :f1, :f1, nothing]
69-
# Dataframe
70-
adjDf = getAdjacencyMatrixDataFrame(dfg)
71-
@test size(adjDf) == (1,4)
72-
end
73-
74-
# Now make a complex graph for connectivity tests
75-
numNodes = 10
76-
dfg = GraphsDFG()
77-
verts = map(n -> DFGVariable(Symbol("x$n")), 1:numNodes)
78-
map(v -> addVariable!(dfg, v), verts)
79-
map(n -> addFactor!(dfg, DFGFactor(Symbol("x$(n)x$(n+1)f1")), [verts[n], verts[n+1]]), 1:(numNodes-1))
80-
# map(n -> addFactor!(dfg, [verts[n], verts[n+2]], DFGFactor(Symbol("x$(n)x$(n+2)f2"))), 1:2:(numNodes-2))
81-
82-
@testset "Getting Neighbors" begin
83-
global dfg,verts
84-
# Get neighbors tests
85-
@test getNeighbors(dfg, verts[1]) == [:x1x2f1]
86-
neighbors = getNeighbors(dfg, getFactor(dfg, :x1x2f1))
87-
@test all([v in [:x1, :x2] for v in neighbors])
88-
# Testing aliases
89-
@test getNeighbors(dfg, getFactor(dfg, :x1x2f1)) == ls(dfg, getFactor(dfg, :x1x2f1))
90-
@test getNeighbors(dfg, :x1x2f1) == ls(dfg, :x1x2f1)
91-
end
92-
93-
@testset "Getting Subgraphs" begin
94-
# Subgraphs
95-
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 2)
96-
# Only returns x1 and x2
97-
@test setdiff([:x1, :x1x2f1, :x2], map(n -> n.label, [ls(dfgSubgraph)..., lsf(dfgSubgraph)...])) == []
98-
# Test include orphan factorsVoid
99-
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 1, true)
100-
@test setdiff([:x1, :x1x2f1], map(n -> n.label, [ls(dfgSubgraph)..., lsf(dfgSubgraph)...])) == []
101-
# Test adding to the dfg
102-
dfgSubgraph = getSubgraphAroundNode(dfg, verts[1], 2, true, dfgSubgraph)
103-
@test setdiff([:x1, :x1x2f1, :x2], map(n -> n.label, [ls(dfgSubgraph)..., lsf(dfgSubgraph)...])) == []
104-
end
6+
# Test each interface
7+
apis = [GraphsDFG]
8+
global testDFGAPI = nothing
9+
for api in apis
10+
global testDFGAPI = api
11+
include("interfaceTests.jl")
12+
end
13+
# Test other interfaces

0 commit comments

Comments
 (0)