Skip to content
This repository

DirectedGraph Specs : Removing a vertex doesn't remove edges from the graph #304

Merged
merged 5 commits into from over 1 year ago

2 participants

प्रथमेश Thomas E Enebo
प्रथमेश

Removing a vertex from a graph doesn't remove the edges from the graph itself. So after removing edges associated with vertex, i deleted it from the associated graph also.

Thomas E Enebo enebo merged commit 33b6869 into from September 19, 2012
Thomas E Enebo enebo closed this September 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 5 unique commits by 1 author.

Sep 18, 2012
Added Bootstrap information to spec 4056edd
Added test for checking class of newly created object 0889a96
Added tests for adding and removing edges 18726f2
Removed type checking spec 765dff6
Fixed removing of edges after deleting a vertex 7a1f068
This page is out of date. Refresh to see the latest.
43  spec/ir/directed_graph/directed_graph_spec.rb
... ...
@@ -0,0 +1,43 @@
  1
+require 'jruby'
  2
+require 'java'
  3
+require 'rspec'
  4
+import 'org.jruby.ir.util.DirectedGraph'
  5
+# This is spec for Directed Graph Library
  6
+
  7
+describe "Directed Graph Utility" do
  8
+
  9
+  before do
  10
+    @graph = DirectedGraph.new
  11
+    @graph.addEdge(1,2,'simple')
  12
+    @graph.addEdge(2,3,'simple')
  13
+    @graph.addEdge(3,4,'simple')
  14
+    @graph.addEdge(4,1,'simple')
  15
+  end
  16
+
  17
+  it "should add an edge to newly created graph" do
  18
+    @graph.edges.size.should == 4
  19
+    @graph.addEdge(4,5,'simple')
  20
+    @graph.edges.size.should == 5
  21
+  end
  22
+
  23
+  it "should remove an existing edge from a graph" do
  24
+    @graph.edges.size.should == 4
  25
+    @graph.removeEdge(1,2)
  26
+    @graph.edges.size.should == 3
  27
+  end
  28
+
  29
+  it "should not delete a non-existent edge from the graph" do
  30
+    @graph.edges.size.should == 4
  31
+    @graph.removeEdge(2,1)
  32
+    @graph.edges.size.should == 4
  33
+  end
  34
+
  35
+  it "should remove a vertex and its associated edges" do
  36
+    @graph.removeVertexFor(3)
  37
+    @graph.edges.size.should == 2
  38
+    @graph.vertices.size.should == 3
  39
+    @graph.removeVertexFor(2)
  40
+    @graph.vertices.size.should == 2
  41
+  end
  42
+
  43
+end
2  src/org/jruby/ir/util/Vertex.java
@@ -57,6 +57,7 @@ public boolean removeEdgeTo(Vertex destination) {
57 57
     public void removeAllIncomingEdges() {
58 58
         for (Edge edge: getIncomingEdges()) {
59 59
             edge.getSource().getOutgoingEdges().remove(edge);
  60
+            graph.edges().remove(edge);
60 61
         }
61 62
         incoming = null;
62 63
     }
@@ -64,6 +65,7 @@ public void removeAllIncomingEdges() {
64 65
     public void removeAllOutgoingEdges() {
65 66
         for (Edge edge: getOutgoingEdges()) {
66 67
             edge.getDestination().getIncomingEdges().remove(edge);
  68
+            graph.edges().remove(edge);
67 69
         }
68 70
         outgoing = null;
69 71
     }
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.