projects
/
graph.njae.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merged in SimpleCov from master#
[graph.njae.git]
/
spec
/
graph
/
edge_spec.rb
diff --git
a/spec/graph/edge_spec.rb
b/spec/graph/edge_spec.rb
index bd823bfd919ab882fed7d7267710413018b648e6..23537560ba40be5ce0ef39d277710951b8f43081 100644
(file)
--- a/
spec/graph/edge_spec.rb
+++ b/
spec/graph/edge_spec.rb
@@
-7,28
+7,38
@@
module GraphNjae
let(:v2) {Vertex.new :name => :v2}
let(:v3) {Vertex.new :name => :v3}
let(:v2) {Vertex.new :name => :v2}
let(:v3) {Vertex.new :name => :v3}
- describe
"#initialize"
do
- it
"creates an empty edge"
do
+ describe
'#initialize'
do
+ it
'creates an empty edge'
do
e = Edge.new
e.connections.should be_empty
end
e = Edge.new
e.connections.should be_empty
end
- it
"creates an edge with some parameters"
do
- e = Edge.new :value1 => 1, :value2 =>
"value2"
, :value3 => :v3
+ it
'creates an edge with some parameters'
do
+ e = Edge.new :value1 => 1, :value2 =>
'value2'
, :value3 => :v3
e.value1.should == 1
e.value1.should == 1
- e.value2.should ==
"value2"
+ e.value2.should ==
'value2'
e.value3.should == :v3
e.value4.should be_nil
end
end # #initialize
e.value3.should == :v3
e.value4.should be_nil
end
end # #initialize
- describe
"adds attribues"
do
- it
"adds then reports arbitrary attributes"
do
+ describe
'adds attribues'
do
+ it
'adds then reports arbitrary attributes'
do
e.score = 15
e.score.should == 15
end
end # adds attributes
e.score = 15
e.score.should == 15
end
end # adds attributes
+ 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
describe "#<<" do
it "adds a new vertex to an edge (with a connection)" do
e.connections.should be_empty
@@
-45,7
+55,7
@@
module GraphNjae
v2.edges.should include(e)
end
v2.edges.should include(e)
end
- it
"adds several vertices to an edge"
do
+ it
'adds several vertices to an edge'
do
e.connections.should be_empty
e << v1 << v2
e.vertices.should include(v1)
e.connections.should be_empty
e << v1 << v2
e.vertices.should include(v1)
@@
-53,7
+63,7
@@
module GraphNjae
e.should have(2).vertices
end
e.should have(2).vertices
end
- it
"adds a self-loop"
do
+ it
'adds a self-loop'
do
e.connections.should be_empty
e << v1 << v1
e.vertices.should include(v1)
e.connections.should be_empty
e << v1 << v1
e.vertices.should include(v1)
@@
-62,8
+72,8
@@
module GraphNjae
end
end # #<<
end
end # #<<
- describe
"connection_at"
do
- it
"returns the connection that links to a vertex"
do
+ describe
'connection_at'
do
+ it
'returns the connection that links to a vertex'
do
e.connections.should be_empty
e << v1 << v2
e.connections.should be_empty
e << v1 << v2
@@
-71,14
+81,14
@@
module GraphNjae
e.connection_at(v2).end.should be v2
end
e.connection_at(v2).end.should be v2
end
- it
"returns nil if there is no connection to that vertex"
do
+ it
'returns nil if there is no connection to that vertex'
do
e.connections.should be_empty
e << v1 << v2
e.connection_at(v3).should be nil
end
e.connections.should be_empty
e << v1 << v2
e.connection_at(v3).should be nil
end
- it
"returns the vertex for a self-loop"
do
+ it
'returns the vertex for a self-loop'
do
e.connections.should be_empty
e << v1 << v1
e.connections.should be_empty
e << v1 << v1
@@
-86,8
+96,8
@@
module GraphNjae
end
end # #connection_at
end
end # #connection_at
- describe
"other_end"
do
- it
"returns the vertex at the other end of the given one"
do
+ describe
'other_end'
do
+ it
'returns the vertex at the other end of the given one'
do
e.connections.should be_empty
e << v1 << v2
e.connections.should be_empty
e << v1 << v2
@@
-95,44
+105,42
@@
module GraphNjae
e.other_end(v2).should be v1
end
e.other_end(v2).should be v1
end
- it
"returns the same vertex in a self-loop"
do
+ it
'returns the same vertex in a self-loop'
do
e.connections.should be_empty
e << v1 << v1
e.other_end(v1).should be v1
end
e.connections.should be_empty
e << v1 << v1
e.other_end(v1).should be v1
end
- it
"returns one of the connected edges if given a vertex not connected to it"
do
+ it
'returns one of the connected edges if given a vertex not connected to it'
do
e.connections.should be_empty
e << v1 << v2
[v1, v2].should include e.other_end(v3)
end
e.connections.should be_empty
e << v1 << v2
[v1, v2].should include e.other_end(v3)
end
- it
"returns nil if it can't return something sensible"
do
+ it
'returns nil if it cannot return something sensible'
do
e.other_end(v1).should be_nil
e << v1
e.other_end(v1).should be_nil
end
end # other_end
e.other_end(v1).should be_nil
e << v1
e.other_end(v1).should be_nil
end
end # other_end
- describe
"#to_dot"
do
- it
"describes an edge in dot notation"
do
+ describe
'#to_dot'
do
+ it
'describes an edge in dot notation'
do
e << v1 << v2
e << v1 << v2
-
e.to_dot.should == "#{v1.object_id.to_s} -- #{v2.object_id.to_s};"
end
e.to_dot.should == "#{v1.object_id.to_s} -- #{v2.object_id.to_s};"
end
- it
"describes an edge in dot notation, using given attributes"
do
+ it
'describes an edge in dot notation, using given attributes'
do
e << v1 << v2
e << v1 << v2
- #vdot = v1.to_dot :label => :name, :shape => :shape
- #vdot.should == "#{v.object_id.to_s} {label = \"vertex\", shape = \"house\"};"
+ e.name = 'Edge name'
+ edot = e.to_dot :label => :name
+ edot.should == "#{v1.object_id.to_s} -- #{v2.object_id.to_s} {label = \"#{e.name}\"};"
end
end
-
- it
"describes an edge in dot notation, given a block"
do
+ it
'describes an edge in dot notation, given a block'
do
e << v1 << v2
e << v1 << v2
-
e.to_dot {|e| e.object_id.to_s}.should == e.object_id.to_s
end
end # dot
e.to_dot {|e| e.object_id.to_s}.should == e.object_id.to_s
end
end # dot
@@
-141,8
+149,8
@@
module GraphNjae
describe Connection do
let (:c) {Connection.new }
describe Connection do
let (:c) {Connection.new }
- describe
"adds attribues"
do
- it
"adds then reports arbitrary attributes"
do
+ describe
'adds attribues'
do
+ it
'adds then reports arbitrary attributes'
do
c.score = 15
c.score.should == 15
end
c.score = 15
c.score.should == 15
end