Permalink
Browse files

Add ability to delete edges using 'delete_edge'. Closes #5

  • Loading branch information...
1 parent ebe24f4 commit ec7211ac86c03424ac3fa762a41e0de8e13aa26b @D4L committed Jan 6, 2013
@@ -22,3 +22,4 @@ class Graph
require "abstract_graph/graph/delete_vertex"
require "abstract_graph/graph/add_edge"
require "abstract_graph/graph/has_edge"
+require "abstract_graph/graph/delete_edge"
@@ -0,0 +1,21 @@
+# required in "abstract_graph/graph"
+
+module AbstractGraph
+ class Graph
+
+ # delete an edge in a replicated graph
+ # p: String s represents the name of the edge
+ def delete_edge( s )
+ other = self.dup
+ other.delete_edge! s
+ end
+
+ # delete an edge in a current graph
+ # p: String s represents the name of the edge
+ def delete_edge!( s )
+ @edges.delete s
+ self
+ end
+
+ end
+end
@@ -0,0 +1,56 @@
+require 'spec_helper'
+
+module AbstractGraph
+ describe Graph do
+
+ before :all do
+ @vertex1 = "Vertex1"
+ @vertex2 = "Vertex2"
+ @edge = "MyEdge"
+ end
+
+ before :each do
+ @graph = Graph.new
+ @graph.add_vertex @vertex1
+ @graph.add_vertex @vertex2
+ @graph.add_edge @edge, @vertex1, @vertex2
+ end
+
+ describe "#delete_edge(String)" do
+
+ it "returns an object of class Graph" do
+ @graph.delete_edge( @edge ).should be_an_instance_of(Graph)
+ end
+
+ it "returns an object without the edge" do
+ nextGraph = @graph.delete_edge( @edge )
+ nextGraph.has_edge?( @edge ).should be_false
+ end
+
+ it "does not modify the original graph" do
+ @graph.delete_edge( @edge )
+ @graph.has_edge?( @edge ).should be_true
+ end
+
+ end
+
+ describe "#delete_edge!(String)" do
+
+ it "returns an object of class Graph" do
+ @graph.delete_edge!( @edge ).should be_an_instance_of(Graph)
+ end
+
+ it "returns an object without the edge" do
+ nextGraph = @graph.delete_edge!( @edge )
+ nextGraph.has_edge?( @edge ).should be_false
+ end
+
+ it "removes the edge from the original graph" do
+ @graph.delete_edge!( @edge )
+ @graph.has_edge?( @edge ).should be_false
+ end
+
+ end
+
+ end
+end

0 comments on commit ec7211a

Please sign in to comment.