Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specs for DirectedGraph Library #307

Merged
merged 3 commits into from
Sep 21, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions spec/ir/directed_graph/directed_graph_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'java' require 'java'
require 'rspec' require 'rspec'
import 'org.jruby.ir.util.DirectedGraph' import 'org.jruby.ir.util.DirectedGraph'

# This is spec for Directed Graph Library # This is spec for Directed Graph Library


describe "Directed Graph Utility" do describe "Directed Graph Utility" do
Expand Down Expand Up @@ -40,4 +41,24 @@
@graph.vertices.size.should == 2 @graph.vertices.size.should == 2
end 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 end
3 changes: 3 additions & 0 deletions src/org/jruby/ir/util/DirectedGraph.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public void removeVertexFor(T data) {
vertex.removeAllEdges(); vertex.removeAllEdges();
} }


/**
* @return the number of vertices in the graph.
*/
public int size() { public int size() {
return allData().size(); return allData().size();
} }
Expand Down