Specs for DirectedGraph Library #307

Merged
merged 3 commits into from Sep 21, 2012
Jump to file or symbol
Failed to load files and symbols.
+24 −0
Split
@@ -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
@@ -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();
}