if vertex_block.nil?
dot << v.to_dot(vertex_args)
else
- dot << v.do_dot(&vertex_block)
+ dot << v.to_dot(&vertex_block)
end
dot << "\n"
end
if edge_block.nil?
dot << e.to_dot(edge_args)
else
- dot << e.do_dot(&lambda {edge_block})
+ dot << e.to_dot(&edge_block)
end
dot << "\n"
end
v1 = Vertex.new(:name => :v1)
v2 = Vertex.new(:name => :v2)
g.connect(v1, v2, :type => :edge_type)
- gdot = g.to_dot(:vertex_block => lambda {|v| v.name})
+ gdot = g.to_dot(:vertex_block => lambda {|v| v.name.to_s + ';'})
gdot.should == "graph {\n#{v1.name};\n#{v2.name};\n#{v1.object_id.to_s} -- #{v2.object_id.to_s};\n}"
end
+ it "gives the dot notation of a simple graph, with vertex and edge attributes" do
+ v1 = Vertex.new(:name => :v1)
+ v2 = Vertex.new(:name => :v2)
+ g.connect(v1, v2, :type => :edge_type)
+ gdot = g.to_dot(:edge_args => {:label => :type}, :vertex_args => {:label => :name})
+ gdot.should == "graph {\n#{v1.object_id.to_s} {label = \"#{v1.name}\"};\n#{v2.object_id.to_s} {label = \"#{v2.name}\"};\n#{v1.object_id.to_s} -- #{v2.object_id.to_s} {label = \"#{g.edges[0].type}\"};\n}"
+ end
+
+ it "gives the dot notation of a simple graph, with vertices and edges generated by a block" do
+ v1 = Vertex.new(:name => :v1)
+ v2 = Vertex.new(:name => :v2)
+ g.connect(v1, v2, :type => :edge_type)
+ gdot = g.to_dot(:vertex_block => lambda {|v| v.name.to_s + ';'},
+ :edge_block => lambda {|e| "#{e.vertices[0].name.to_s} -- #{e.vertices[1].name.to_s} {label = \"#{e.type.to_s}\"};"})
+ gdot.should == "graph {\n#{v1.name};\n#{v2.name};\n#{v1.name} -- #{v2.name} {label = \"#{g.edges[0].type}\"};\n}"
+ end
+
end # #to_dot
describe 'product' do