X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=spec%2Fgraph%2Fvertex_spec.rb;fp=spec%2Fgraph%2Fvertex_spec.rb;h=9d109db3aced26dfdb072fdea7eed4ca9439985b;hb=282a96d68535bd39b4dcd08ff805ccfcfd8b9f10;hp=3689c0b92faf25b0ec097f732e9b6545128b5f25;hpb=99e4223d9b3baef392d4a6b0b996078f06fcadf7;p=graph.njae.git diff --git a/spec/graph/vertex_spec.rb b/spec/graph/vertex_spec.rb index 3689c0b..9d109db 100644 --- a/spec/graph/vertex_spec.rb +++ b/spec/graph/vertex_spec.rb @@ -4,30 +4,30 @@ module GraphNjae describe Vertex do let (:v) { Vertex.new } - describe "#initialize" do - it "creates an empty vertex" do + describe '#initialize' do + it 'creates an empty vertex' do v = Vertex.new v.edges.should be_empty end - it "creates a vertex with some parameters" do - v = Vertex.new :value1 => 1, :value2 => "value2", :value3 => :v3 + it 'creates a vertex with some parameters' do + v = Vertex.new :value1 => 1, :value2 => 'value2', :value3 => :v3 v.value1.should == 1 - v.value2.should == "value2" + v.value2.should == 'value2' v.value3.should == :v3 v.value4.should be_nil end end # #initialize - describe "adds attribues" do - it "adds then reports arbitrary attributes" do + describe 'adds attribues' do + it 'adds then reports arbitrary attributes' do v.score = 15 v.score.should == 15 end end # adds attributes - describe "#<<" do - it "adds a single edge between vertices" do + describe '#<<' do + it 'adds a single edge between vertices' do v.neighbours.should be_empty v.edges.should be_empty @@ -49,7 +49,7 @@ module GraphNjae v1.neighbours.should_not include(v1) end - it "adds a single edge as a self-loop" do + it 'adds a single edge as a self-loop' do v.neighbours.should be_empty v.edges.should be_empty @@ -61,8 +61,8 @@ module GraphNjae end end # #<< - describe "connect" do - it "connects two vertices" do + describe 'connect' do + it 'connects two vertices' do v1 = Vertex.new v1.id = :v1 # Need this to ensure that v != v1 @@ -88,14 +88,14 @@ module GraphNjae e.should have(2).connections end - it "connects two vertices by an edge with attributes" do + it 'connects two vertices by an edge with attributes' do v1 = Vertex.new v1.id = :v1 e = v.connect(v1, {:type => :edge_type}) e.type.should == :edge_type end - it "creates a self-connection" do + it 'creates a self-connection' do e = v.connect v v.should have(1).neighbours @@ -111,21 +111,21 @@ module GraphNjae e.should have(2).connections end - it "creates a self-connection with an edge with attributes" do + it 'creates a self-connection with an edge with attributes' do e = v.connect(v, {:type => :edge_type}) e.type.should == :edge_type end end # #connect - describe "#neighbours" do - it "finds neighbours of a self loop" do + describe '#neighbours' do + it 'finds neighbours of a self loop' do v << v v.should have(1).neighbours v.neighbours.should include v end - it "finds neighbours on an edge" do + it 'finds neighbours on an edge' do v1 = Vertex.new v << v1 v.should have(1).neighbours @@ -134,7 +134,7 @@ module GraphNjae v1.neighbours.should include v end - it "finds neighbours with multiple edges" do + it 'finds neighbours with multiple edges' do v1 = Vertex.new v1.id = :v1 v << v1 @@ -147,14 +147,14 @@ module GraphNjae v1.neighbours.should_not include v1 end - it "finds neighbours with multiple self loops" do + it 'finds neighbours with multiple self loops' do v << v << v << v v.should have(3).neighbours v.neighbours.should include v v.neighbours.uniq.length.should == 1 end - it "finds neighbours with all sorts of edges" do + it 'finds neighbours with all sorts of edges' do v1 = Vertex.new ; v1.id = :v1 v2 = Vertex.new ; v2.id = :v2 v3 = Vertex.new ; v3.id = :v3 @@ -179,7 +179,7 @@ module GraphNjae v3.neighbours.should include v2 end - it "finds neighbours in graphs with several vertices" do + it 'finds neighbours in graphs with several vertices' do v1 = Vertex.new ; v1.id = :v1 v2 = Vertex.new ; v2.id = :v2 v3 = Vertex.new ; v3.id = :v3 @@ -211,7 +211,7 @@ module GraphNjae v4.neighbours.should_not include v4 end - it "finds neighbours with multiple edges between vertices" do + it 'finds neighbours with multiple edges between vertices' do v1 = Vertex.new ; v1.id = :v1 v2 = Vertex.new ; v2.id = :v2 v3 = Vertex.new ; v3.id = :v3 @@ -243,23 +243,23 @@ module GraphNjae end end # #neighbours - describe "#to_dot" do - it "describes a vertex in dot notation" do + describe '#to_dot' do + it 'describes a vertex in dot notation' do v = Vertex.new v.to_dot.should == "#{v.object_id.to_s};" end - it "describes a vertex in dot notation, using given attributes" do + it 'describes a vertex in dot notation, using given attributes' do v = Vertex.new - v.name = "vertex" - v.shape = "house" + v.name = 'vertex' + v.shape = 'house' vdot = v.to_dot :label => :name, :shape => :shape - vdot.should == "#{v.object_id.to_s} {label = \"vertex\", shape = \"house\"};" + vdot.should == "#{v.object_id.to_s} {label = \"#{v.name}\", shape = \"#{v.shape}\"};" end - it "describes a vertex using a block" do + it 'describes a vertex using a block' do v = Vertex.new - v.field1 = "f1" + v.field1 = 'f1' vdot = v.to_dot {|v| v.field1 + ';'} vdot.should == "#{v.field1};" end