+
+ describe "other_end" do
+ it "returns the vertex at the other end of the given one" do
+ e.connections.should be_empty
+ v1 = Vertex.new :name => :v1
+ v2 = Vertex.new :name => :v2
+ e << v1 << v2
+
+ e.other_end(v1).should be v2
+ e.other_end(v2).should be v1
+ end
+
+ it "returns the same vertex in a self-loop" do
+ e.connections.should be_empty
+ v1 = Vertex.new :name => :v1
+ e << v1 << v1
+
+ e.other_end(v1).should be v1
+ end
+
+ it "returns one of the connected edges if given a vertex not connected to it" do
+ e.connections.should be_empty
+ v1 = Vertex.new :name => :v1
+ v2 = Vertex.new :name => :v2
+ v3 = Vertex.new :name => :v3
+ e << v1 << v2
+
+ [v1, v2].should include e.other_end(v3)
+ end
+
+ it "returns nil if it can't return something sensible" do
+ v1 = Vertex.new :name => :v1
+ e.other_end(v1).should be_nil
+ e << v1
+ e.other_end(v1).should be_nil
+ end
+ end # other_end