end
def to_s
- '<V: ' + self.name + '>'
+ '<V: ' + self.name.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
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 == '<E: test [<V: v1>, <V: v2>] >'
+ 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
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 == '<V: v1>'
+ 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