From: Neil Smith Date: Wed, 18 Jul 2012 08:35:50 +0000 (+0100) Subject: Merged in SimpleCov from master# X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;ds=sidebyside;h=07acbb1582f12f3dcde0351277cc42a36e61e87b;p=graph.njae.git Merged in SimpleCov from master# --- 07acbb1582f12f3dcde0351277cc42a36e61e87b diff --cc lib/graph.njae/vertex.rb index 4ac903c,aca3fa9..def0b66 --- a/lib/graph.njae/vertex.rb +++ b/lib/graph.njae/vertex.rb @@@ -38,24 -40,8 +38,24 @@@ module GraphNja end def to_s - '' + '' end + def to_dot(opts = {}) + if block_given? + yield self + else + dot = self.object_id.to_s + if opts.size > 0 + dot << ' {' + dot << opts.keys.map { |k| + (k.to_s + ' = "' + self.instance_eval(opts[k].to_s).to_s) + '"' + }.join(', ') + dot << '}' + end + dot << ';' + end + end + end end diff --cc spec/graph/edge_spec.rb index 938890f,f4be16b..2353756 --- a/spec/graph/edge_spec.rb +++ b/spec/graph/edge_spec.rb @@@ -29,9 -25,21 +29,19 @@@ module GraphNja end end # adds attributes - describe '#<<' do - it 'adds a new vertex to an edge (with a connection)' do + describe "#to_s" do + it "returns the string form of an edge" do + v1 = Vertex.new :name => :v1 + v2 = Vertex.new :name => :v2 + e.type = :test + e << v1 << v2 + e.to_s.should == ', ] >' + end + end + + describe "#<<" do + it "adds a new vertex to an edge (with a connection)" do e.connections.should be_empty - v1 = Vertex.new :name => :v1 - v2 = Vertex.new :name => :v2 e << v1 e.should have(1).connections e.should have(1).vertices diff --cc spec/graph/vertex_spec.rb index 9d109db,33b9e03..ca9f7eb --- a/spec/graph/vertex_spec.rb +++ b/spec/graph/vertex_spec.rb @@@ -25,9 -25,17 +25,17 @@@ module GraphNja v.score.should == 15 end end # adds attributes + + describe "#to_s" do + it "returns the string form of a vertex" do + v.name = :v1 + v.to_s.should == '' + end + end + - 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