Skip to content

Commit

Permalink
Merge pull request #5 from matbesancon/fix-return
Browse files Browse the repository at this point in the history
Fix return
  • Loading branch information
matbesancon authored Jun 3, 2019
2 parents 47fd0bd + baf583c commit 54bf395
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/VertexSafeGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ LG.vertices(g::VSafeGraph) = (v for v in LG.vertices(g.g) if !(v in g.deleted_ve

LG.has_vertex(g::VSafeGraph, v) = LG.has_vertex(g.g, v) && !(v in g.deleted_vertices)

LG.has_edge(g::VSafeGraph, e) = LG.has_edge(g.g, e)
LG.has_edge(g::VSafeGraph, src, dst) = LG.has_edge(g.g, src, dst)
LG.has_edge(g::VSafeGraph, edge::LG.AbstractEdge) = LG.has_edge(g.g, LG.src(edge), LG.dst(edge))

LG.add_vertex!(g::VSafeGraph) = LG.add_vertex!(g.g)

LG.rem_edge!(g::VSafeGraph, v1, v2) = LG.rem_edge!(g.g, v1, v2)

Base.copy(g::VSafeGraph) = VSafeGraph(copy(g.g), copy(g.deleted_vertices))


function LG.outneighbors(g::VSafeGraph, v)
if LG.has_vertex(g, v)
LG.outneighbors(g.g, v)
Expand All @@ -60,12 +60,12 @@ end
function LG.add_edge!(g::VSafeGraph, v1, v2)
if !LG.has_vertex(g, v1) || !LG.has_vertex(g, v2)
return false
else
LG.add_edge!(g.g, v1, v2)
return true
end
return LG.add_edge!(g.g, v1, v2)
end

LG.add_edge!(g::VSafeGraph, edge::LG.AbstractEdge) = LG.add_edge!(g, LG.src(edge), LG.dst(edge))

function LG.rem_vertex!(g::VSafeGraph, v1)
if !LG.has_vertex(g, v1) || v1 in g.deleted_vertices
return false
Expand Down
23 changes: 20 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,32 @@ const LG = LightGraphs
g1 = VSafeGraph(nv)
@test LG.nv(g1) == nv
@test LG.nv(g1.g) == nv

@test LG.ne(g1) == 0
@test LG.add_edge!(g1, 1, 2)
g1_copy = copy(g1)
@test LG.ne(g1) == 1 == LG.ne(g1_copy)
@test LG.add_edge!(g1, 1, 3)
@test LG.ne(g1) == 2 == LG.ne(g1_copy) + 1

g2_inner = LG.CompleteGraph(nv)
g2 = VSafeGraph(g2_inner)
@test LG.nv(g2) == LG.nv(g2_inner)
@test LG.ne(g2) == LG.ne(g2_inner)

@test all(sort(collect(LG.vertices(g2))) .== sort(collect(LG.vertices(g2_inner))))

@test LG.has_edge(g2, 1, 2)
@test LG.has_edge(g2, LG.SimpleEdge(1, 2))
@test LG.edgetype(g2) == LG.edgetype(g2_inner)

g3 = VSafeGraph(LG.CompleteDiGraph(30))
@test !LG.add_edge!(g3, 1, 2) # no possible addition on a complete graph
@test !LG.add_edge!(g3, LG.SimpleEdge(1, 2))
@test LG.is_directed(g3)
@test !LG.is_directed(g2)
@test LG.is_directed(typeof(g3))
@test !LG.is_directed(typeof(g2))
@test !LG.is_directed(VSafeGraph)
end

@testset "Vertex deletion" begin
Expand All @@ -44,6 +59,9 @@ end

@test LG.ne(inner) == LG.ne(g)
end
@test LG.add_vertex!(g)
@test LG.nv(g) == nv - nrm + 1
@test LG.nv(g.g) == nv + 1
end


Expand Down Expand Up @@ -74,9 +92,8 @@ end
if added_ok
nea += 1
end

@test LG.ne(g) == ne + nea
@test LG.nv(g) == nv - nrv
@test LG.nv(g) == nv - nrv
end
end

Expand Down

0 comments on commit 54bf395

Please sign in to comment.