From 54f6ce8c6e9a2c068c6b1bdfa096dcabb4e0ef1c Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Wed, 5 Dec 2012 18:34:50 +0530 Subject: [PATCH 1/4] Added description for vertexFor method --- src/org/jruby/ir/util/DirectedGraph.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/org/jruby/ir/util/DirectedGraph.java b/src/org/jruby/ir/util/DirectedGraph.java index b8beed7ade6..73f57238e71 100644 --- a/src/org/jruby/ir/util/DirectedGraph.java +++ b/src/org/jruby/ir/util/DirectedGraph.java @@ -64,6 +64,9 @@ public Vertex findVertexFor(T data) { return vertices.get(data); } + /** + * @return vertex for given data. If vertex is not present it creates vertex and returns it. + */ public Vertex vertexFor(T data) { Vertex vertex = vertices.get(data); From b6edf4a29157ef5ecd4e050c79f9353200ed0daf Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Thu, 6 Dec 2012 00:25:32 +0530 Subject: [PATCH 2/4] Added spec for allData method of DirectedGraph.java --- spec/ir/directed_graph/directed_graph_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/ir/directed_graph/directed_graph_spec.rb b/spec/ir/directed_graph/directed_graph_spec.rb index 7272e90f4da..ddaa80c6f31 100644 --- a/spec/ir/directed_graph/directed_graph_spec.rb +++ b/spec/ir/directed_graph/directed_graph_spec.rb @@ -70,4 +70,16 @@ @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 + end From 9deef648a66d8fd4ed1b119419410b28492b87b4 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Thu, 6 Dec 2012 00:37:34 +0530 Subject: [PATCH 3/4] Added spec for removeEdge(Edge edge) method in DirectedGraph.java --- spec/ir/directed_graph/directed_graph_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/ir/directed_graph/directed_graph_spec.rb b/spec/ir/directed_graph/directed_graph_spec.rb index ddaa80c6f31..2d5a1fc12a2 100644 --- a/spec/ir/directed_graph/directed_graph_spec.rb +++ b/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 From 9a3eb797ce136349f3866fc2ae9b35be360fb3df Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Thu, 6 Dec 2012 00:50:17 +0530 Subject: [PATCH 4/4] Added spec for getInorderData method of DirectedGraph.java --- spec/ir/directed_graph/directed_graph_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/ir/directed_graph/directed_graph_spec.rb b/spec/ir/directed_graph/directed_graph_spec.rb index 2d5a1fc12a2..383fb66b4cc 100644 --- a/spec/ir/directed_graph/directed_graph_spec.rb +++ b/spec/ir/directed_graph/directed_graph_spec.rb @@ -84,4 +84,14 @@ 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