X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=spec%2Fgraph%2Fvertex_spec.rb;h=3689c0b92faf25b0ec097f732e9b6545128b5f25;hb=99e4223d9b3baef392d4a6b0b996078f06fcadf7;hp=b193bc81057558d24f9cf10ca7674937cb5d570d;hpb=804c1d3850e599aea8cb3258d1a875be148a3b30;p=graph.njae.git diff --git a/spec/graph/vertex_spec.rb b/spec/graph/vertex_spec.rb index b193bc8..3689c0b 100644 --- a/spec/graph/vertex_spec.rb +++ b/spec/graph/vertex_spec.rb @@ -85,9 +85,16 @@ module GraphNjae e.vertices.should include(v) e.vertices.should include(v1) - e.should have(2).connections + e.should have(2).connections end + 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 e = v.connect v @@ -104,6 +111,11 @@ module GraphNjae e.should have(2).connections end + 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 @@ -230,5 +242,27 @@ module GraphNjae v3.neighbours.uniq.length.should == 1 end end # #neighbours + + 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 + v = Vertex.new + 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\"};" + end + + it "describes a vertex using a block" do + v = Vertex.new + v.field1 = "f1" + vdot = v.to_dot {|v| v.field1 + ';'} + vdot.should == "#{v.field1};" + end + end # #to_dot end end