Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added Specs for IR and renamed a method in Vertex.java #833

Merged
merged 3 commits into from

2 participants

@prathamesh-sonpatki

1) Added specs for methods in Vertex.java
2) Rename getSingleEdge to getFirstEdge as that's the purpose of that method.

@enebo enebo merged commit d53242b into from
@prathamesh-sonpatki prathamesh-sonpatki deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
59 spec/ir/directed_graph/vertex_spec.rb
@@ -65,10 +65,65 @@
context "Destination of all of the outgoing edges from the current vertex doesn't match with given destination" do
it "returns false" do
- fake = Vertex.new(@graph, "baz", 3)
- expect(@source.removeEdgeTo(fake)).to be false
+ non_existent_destination = Vertex.new(@graph, "baz", 3)
+ expect(@source.removeEdgeTo(non_existent_destination)).to be false
end
end
end
+
+ describe "Remove all incoming edges" do
+
+ before do
+ @a = Vertex.new(@graph, "foo", 1)
+ @b = Vertex.new(@graph, "bar", 2)
+ @c = Vertex.new(@graph, "baz", 2)
+ @b.addEdgeTo(@a)
+ @c.addEdgeTo(@a)
+ end
+
+ it "removes all incoming edges to the vertex" do
+ @a.removeAllIncomingEdges()
+ expect(@a.inDegree).to eq 0
+ end
+
+ end
+
+ describe "Remove all outgoing edges" do
+
+ before do
+ @a = Vertex.new(@graph, "foo", 1)
+ @b = Vertex.new(@graph, "bar", 2)
+ @c = Vertex.new(@graph, "baz", 2)
+ @a.addEdgeTo(@b)
+ @a.addEdgeTo(@c)
+ end
+
+ it "removes all outgoing edges from the vertex" do
+ @a.removeAllOutgoingEdges()
+ expect(@a.outDegree).to eq 0
+ end
+
+ end
+
+ describe "Remove all edges" do
+
+ before do
+ @a = Vertex.new(@graph, "foo", 1)
+ @b = Vertex.new(@graph, "bar", 2)
+ @c = Vertex.new(@graph, "baz", 2)
+ @a.addEdgeTo(@b)
+ @a.addEdgeTo(@c)
+ @c.addEdgeTo(@a)
+ @b.addEdgeTo(@a)
+ end
+
+ it "removes all edges from the vertex" do
+ @a.removeAllEdges()
+ expect(@a.outDegree).to eq 0
+ expect(@a.inDegree).to eq 0
+ end
+
+ end
+
end
View
22 src/org/jruby/ir/util/Vertex.java
@@ -102,13 +102,13 @@ public int outDegree() {
}
public T getIncomingSourceData() {
- Edge<T> edge = getSingleEdge(getIncomingEdges().iterator(), "");
+ Edge<T> edge = getFirstEdge(getIncomingEdges().iterator(), "");
return edge == null ? null : edge.getSource().getData();
}
public T getIncomingSourceDataOfType(Object type) {
- Edge<T> edge = getSingleEdge(getIncomingEdgesOfType(type).iterator(), type);
+ Edge<T> edge = getFirstEdge(getIncomingEdgesOfType(type).iterator(), type);
return edge == null ? null : edge.getSource().getData();
}
@@ -142,18 +142,18 @@ public T getIncomingSourceDataOfType(Object type) {
}
public T getOutgoingDestinationData() {
- Edge<T> edge = getSingleEdge(getOutgoingEdges().iterator(), "");
+ Edge<T> edge = getFirstEdge(getOutgoingEdges().iterator(), "");
return edge == null ? null : edge.getDestination().getData();
}
public T getOutgoingDestinationDataOfType(Object type) {
- Edge<T> edge = getSingleEdge(getOutgoingEdgesOfType(type).iterator(), type);
+ Edge<T> edge = getFirstEdge(getOutgoingEdgesOfType(type).iterator(), type);
return edge == null ? null : edge.getDestination().getData();
}
- private Edge<T> getSingleEdge(Iterator<Edge<T>> iterator, Object type) {
+ private Edge<T> getFirstEdge(Iterator<Edge<T>> iterator, Object type) {
if (iterator.hasNext()) {
Edge<T> edge = iterator.next();
@@ -166,27 +166,27 @@ public T getOutgoingDestinationDataOfType(Object type) {
}
public Edge<T> getIncomingEdgeOfType(Object type) {
- return getSingleEdge(getIncomingEdgesOfType(type).iterator(), type);
+ return getFirstEdge(getIncomingEdgesOfType(type).iterator(), type);
}
public Edge<T> getOutgoingEdgeOfType(Object type) {
- return getSingleEdge(getOutgoingEdgesOfType(type).iterator(), type);
+ return getFirstEdge(getOutgoingEdgesOfType(type).iterator(), type);
}
/**
- * Get single incoming edge of any type and assert if there is more than
+ * Get first incoming edge of any type and assert if there is more than
* one.
*/
public Edge<T> getIncomingEdge() {
- return getSingleEdge(getIncomingEdgesNotOfType(null).iterator(), null);
+ return getFirstEdge(getIncomingEdgesNotOfType(null).iterator(), null);
}
/**
- * Get single outgoing edge of any type and assert if there is more than
+ * Get first outgoing edge of any type and assert if there is more than
* one.
*/
public Edge<T> getOutgoingEdge() {
- return getSingleEdge(getOutgoingEdgesNotOfType(null).iterator(), null);
+ return getFirstEdge(getOutgoingEdgesNotOfType(null).iterator(), null);
}
public Set<Edge<T>> getIncomingEdges() {
Something went wrong with that request. Please try again.