Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 5 commits into from

2 participants

@prathamesh-sonpatki

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.

@enebo enebo merged commit 33b6869 into jruby:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 18, 2012
  1. Added Bootstrap information to spec

    Prathamesh Sonpatki authored
  2. Added test for checking class of newly created object

    Prathamesh Sonpatki authored
  3. Added tests for adding and removing edges

    Prathamesh Sonpatki authored
  4. Removed type checking spec

    Prathamesh Sonpatki authored
  5. Fixed removing of edges after deleting a vertex

    Prathamesh Sonpatki authored
This page is out of date. Refresh to see the latest.
View
43 spec/ir/directed_graph/directed_graph_spec.rb
@@ -0,0 +1,43 @@
+require 'jruby'
+require 'java'
+require 'rspec'
+import 'org.jruby.ir.util.DirectedGraph'
+# This is spec for Directed Graph Library
+
+describe "Directed Graph Utility" do
+
+ before do
+ @graph = DirectedGraph.new
+ @graph.addEdge(1,2,'simple')
+ @graph.addEdge(2,3,'simple')
+ @graph.addEdge(3,4,'simple')
+ @graph.addEdge(4,1,'simple')
+ end
+
+ it "should add an edge to newly created graph" do
+ @graph.edges.size.should == 4
+ @graph.addEdge(4,5,'simple')
+ @graph.edges.size.should == 5
+ end
+
+ it "should remove an existing edge from a graph" do
+ @graph.edges.size.should == 4
+ @graph.removeEdge(1,2)
+ @graph.edges.size.should == 3
+ end
+
+ it "should not delete a non-existent edge from the graph" do
+ @graph.edges.size.should == 4
+ @graph.removeEdge(2,1)
+ @graph.edges.size.should == 4
+ end
+
+ it "should remove a vertex and its associated edges" do
+ @graph.removeVertexFor(3)
+ @graph.edges.size.should == 2
+ @graph.vertices.size.should == 3
+ @graph.removeVertexFor(2)
+ @graph.vertices.size.should == 2
+ end
+
+end
View
2  src/org/jruby/ir/util/Vertex.java
@@ -57,6 +57,7 @@ public boolean removeEdgeTo(Vertex destination) {
public void removeAllIncomingEdges() {
for (Edge edge: getIncomingEdges()) {
edge.getSource().getOutgoingEdges().remove(edge);
+ graph.edges().remove(edge);
}
incoming = null;
}
@@ -64,6 +65,7 @@ public void removeAllIncomingEdges() {
public void removeAllOutgoingEdges() {
for (Edge edge: getOutgoingEdges()) {
edge.getDestination().getIncomingEdges().remove(edge);
+ graph.edges().remove(edge);
}
outgoing = null;
}
Something went wrong with that request. Please try again.