diff --git a/src/abstractnamedgraph.jl b/src/abstractnamedgraph.jl index d83e836..d2b15eb 100644 --- a/src/abstractnamedgraph.jl +++ b/src/abstractnamedgraph.jl @@ -381,7 +381,7 @@ function union(graph1::AbstractNamedGraph, graph2::AbstractNamedGraph) return union_graph end -function insert_vertex!(graph::AbstractNamedGraph, vertex) +function set_vertex!(graph::AbstractNamedGraph, vertex) add_vertex!(parent_graph(graph)) # Update the vertex list push!(vertices(graph), vertex) @@ -391,16 +391,24 @@ function insert_vertex!(graph::AbstractNamedGraph, vertex) return graph end +function insert_vertex!(graph::AbstractNamedGraph, vertex) + if vertex ∈ vertices(graph) + error("Duplicate vertices not allowed!") + else + set_vertex!(graph, vertex) + end +end + function add_vertex!(graph::AbstractNamedGraph, vertex) if vertex ∈ vertices(graph) return false else - insert_vertex!(graph, vertex) + set_vertex!(graph, vertex) return true end end -function rem_vertex!(graph::AbstractNamedGraph, vertex) +function unset_vertex!(graph::AbstractNamedGraph, vertex) parent_vertex = vertex_to_parent_vertex(graph, vertex) rem_vertex!(parent_graph(graph), parent_vertex) @@ -420,6 +428,23 @@ function rem_vertex!(graph::AbstractNamedGraph, vertex) return graph end +function rem_vertex!(graph::AbstractNamedGraph, vertex) + if vertex ∉ vertices(graph) + return false + else + unset_vertex!(graph, vertex) + return true + end +end + +function delete_vertex!(graph::AbstractNamedGraph, vertex) + if vertex ∉ vertices(graph) + error("vertex not in graph!") + else + unset_vertex!(graph, vertex) + end +end + function add_vertices!(graph::AbstractNamedGraph, vs::Vector) for vertex in vs add_vertex!(graph, vertex) diff --git a/test/test_examples.jl b/test/test_examples.jl index 96a383e..b489ee3 100644 --- a/test/test_examples.jl +++ b/test/test_examples.jl @@ -4,7 +4,9 @@ using Suppressor using Test examples_path = joinpath(pkgdir(NamedGraphs), "examples") -@testset "Run examples: $filename" for filename in readdir(examples_path) +examples_to_exclude = ["partitioning.jl"] +@testset "Run examples: $filename" for filename in + setdiff(readdir(examples_path), examples_to_exclude) if endswith(filename, ".jl") @suppress include(joinpath(examples_path, filename)) end