X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=spec%2Fgraph%2Fgraph_spec.rb;h=88724a472066b9c8d5f656a35adc58df3000f08e;hb=1bd42608db15715f695d7dbaa95e6bf9429bcc2b;hp=7da0bb9c599275ed94e9fdcd04a4df427cf3bd3f;hpb=07acbb1582f12f3dcde0351277cc42a36e61e87b;p=graph.njae.git diff --git a/spec/graph/graph_spec.rb b/spec/graph/graph_spec.rb index 7da0bb9..88724a4 100644 --- a/spec/graph/graph_spec.rb +++ b/spec/graph/graph_spec.rb @@ -131,10 +131,27 @@ module GraphNjae 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