Skip to content
Browse files

Merge pull request #307 from prathamesh-sonpatki/graph-library-tests

Specs for DirectedGraph Library
  • Loading branch information...
2 parents b1fec0d + 7044c83 commit 99ce5c64b9ad7cdfe345529d97cc1ae9cb50a7ef @enebo enebo committed
Showing with 24 additions and 0 deletions.
  1. +21 −0 spec/ir/directed_graph/directed_graph_spec.rb
  2. +3 −0 src/org/jruby/ir/util/DirectedGraph.java
View
21 spec/ir/directed_graph/directed_graph_spec.rb
@@ -2,6 +2,7 @@
require 'java'
require 'rspec'
import 'org.jruby.ir.util.DirectedGraph'
+
# This is spec for Directed Graph Library
describe "Directed Graph Utility" do
@@ -40,4 +41,24 @@
@graph.vertices.size.should == 2
end
+ it "should give vertex for given data" do
+ @graph.vertexFor(2).getData().should == 2
+ end
+
+ it "should create a new vertex if it is not present" do
+ @graph.vertexFor(100).getData().should == 100
+ end
+
+ it "should find already existing vertex" do
+ @graph.findVertexFor(2).getData().should == 2
+ @graph.findVertexFor(100).should == nil
+ end
+
+ it "should give correct size of graph" do
+ @graph.removeEdge(1,2)
+ @graph.size.should == 4
+ @graph.addEdge(5,6,'simple')
+ @graph.size.should == 6
+ end
+
end
View
3 src/org/jruby/ir/util/DirectedGraph.java
@@ -81,6 +81,9 @@ public void removeVertexFor(T data) {
vertex.removeAllEdges();
}
+ /**
+ * @return the number of vertices in the graph.
+ */
public int size() {
return allData().size();
}

0 comments on commit 99ce5c6

Please sign in to comment.
Something went wrong with that request. Please try again.