X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=spec%2Fgraph%2Fedge_spec.rb~;fp=spec%2Fgraph%2Fedge_spec.rb~;h=e4848e59a058dbc2ce3032b5d205303b14a6fc96;hb=624e339a169bd96eb01da7288a8904e0d1830e42;hp=0000000000000000000000000000000000000000;hpb=7f38e9910061e8a71db6dac57327ca1f5d3c27cd;p=graph.njae.git diff --git a/spec/graph/edge_spec.rb~ b/spec/graph/edge_spec.rb~ new file mode 100644 index 0000000..e4848e5 --- /dev/null +++ b/spec/graph/edge_spec.rb~ @@ -0,0 +1,90 @@ +require 'spec_helper' + +module Graph + describe Edge do + let (:e) { Edge.new } + describe "#initialize" do + it "creates an empty edge" do + e = Edge.new + e.connections.should be_empty + end + end # #initialize + + describe "adds attribues" do + it "adds then reports arbitrary attributes" do + e.score = 15 + e.score.should == 15 + end + end # adds attributes + + describe "#<<" do + it "adds a new vertex to an edge (with a connection)" do + e.connections.should be_empty + v1 = Vertex.new + v2 = Vertex.new + e << v1 + e.should have(1).connections + e.should have(1).vertices + e.vertices.should include(v1) + e << v2 + e.should have(2).connections + e.should have(2).vertices + e.vertices.should include(v1) + e.vertices.should include(v2) + end + + it "adds several vertices to an edge" do + e.connections.should be_empty + v1 = Vertex.new + v2 = Vertex.new + e << v1 << v2 + e.vertices.should include(v1) + e.vertices.should include(v2) + e.should have(2).vertices + end + + it "adds a self-loop" do + e.connections.should be_empty + v1 = Vertex.new + e << v1 << v1 + e.vertices.should include(v1) + e.should have(2).vertices + e.vertices.uniq.length.should == 1 + end + end # #<< + + describe "connection_at" do + it "returns the connection that links to a vertex" do + e.connections.should be_empty + v1 = Vertex.new + v2 = Vertex.new + e << v1 << v2 + + e.connection_at(v1).end.should be v1 + e.connection_at(v2).end.should be v2 + end + + it "returns nil if there is no connection to that vertex" do + e.connections.should be_empty + v1 = Vertex.new + v2 = Vertex.new + v3 = Vertex.new + e << v1 << v2 + + e.connection_at(v3).should be nil + end + end # #connection_at + end # Edge + + describe Connection do + let (:c) {Connection.new } + + describe "adds attribues" do + it "adds then reports arbitrary attributes" do + c.score = 15 + c.score.should == 15 + end + end # adds attributes + end # Connection + +end \ No newline at end of file