Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Directed graph library specs #428

Merged
merged 4 commits into from
This page is out of date. Refresh to see the latest.
View
24 spec/ir/directed_graph/directed_graph_spec.rb
@@ -26,6 +26,8 @@
@graph.addEdge(4,5,'bar')
@graph.removeEdge(4,5)
@graph.edges.size.should be 1
+ @graph.removeEdge(@graph.edges.to_a.last)
+ @graph.edges.size.should be 0
end
it "should not delete a non-existent edge from the graph" do
@@ -70,4 +72,26 @@
@graph.size.should be 4
end
+ it "should give all data in the graph" do
+ @graph.allData.size.should be 0
+ @graph.addEdge(1,2,'baz')
+ @graph.allData.each do |key|
+ @graph.findVertexFor(key).should_not be_nil
+ end
+ @graph.removeVertexFor(1)
+ @graph.allData.each do |key|
+ @graph.findVertexFor(key).should_not be_nil
+ end
+ end
+
+ it "should give data in the graph in the order in which it was inserted" do
+ @graph.getInorderData.to_a.size.should be 0
+ @graph.vertexFor(1)
+ @graph.getInorderData.to_a.should eq [1]
+ @graph.addEdge('foo','bar','baz')
+ @graph.getInorderData.to_a.should eq [1,'foo','bar']
+ @graph.removeVertexFor('foo')
+ @graph.getInorderData.to_a.should eq [1,'bar']
+ end
+
end
View
3  src/org/jruby/ir/util/DirectedGraph.java
@@ -64,6 +64,9 @@ public void removeEdge(T source, T destination) {
return vertices.get(data);
}
+ /**
+ * @return vertex for given data. If vertex is not present it creates vertex and returns it.
+ */
public Vertex<T> vertexFor(T data) {
Vertex vertex = vertices.get(data);
Something went wrong with that request. Please try again.