1 require File
.expand_path(File
.dirname(__FILE__
) + '/../spec_helper')
6 let(:v1) {Vertex
.new
:name => :v1}
7 let(:v2) {Vertex
.new
:name => :v2}
8 let(:v3) {Vertex
.new
:name => :v3}
10 describe
'#initialize' do
11 it
'creates an empty edge' do
13 e
.connections
.should be_empty
16 it
'creates an edge with some parameters' do
17 e
= Edge
.new
:value1 => 1, :value2 => 'value2', :value3 => :v3
19 e
.value2
.should
== 'value2'
20 e
.value3
.should
== :v3
21 e
.value4
.should be_nil
25 describe
'adds attribues' do
26 it
'adds then reports arbitrary attributes' do
33 it
'adds a new vertex to an edge (with a connection)' do
34 e
.connections
.should be_empty
36 e
.should
have(1).connections
37 e
.should
have(1).vertices
38 e
.vertices
.should
include(v1
)
39 v1
.edges
.should
include(e
)
41 e
.should
have(2).connections
42 e
.should
have(2).vertices
43 e
.vertices
.should
include(v1
)
44 e
.vertices
.should
include(v2
)
45 v2
.edges
.should
include(e
)
48 it
'adds several vertices to an edge' do
49 e
.connections
.should be_empty
51 e
.vertices
.should
include(v1
)
52 e
.vertices
.should
include(v2
)
53 e
.should
have(2).vertices
56 it
'adds a self-loop' do
57 e
.connections
.should be_empty
59 e
.vertices
.should
include(v1
)
60 e
.should
have(2).vertices
61 e
.vertices
.uniq
.length
.should
== 1
65 describe
'connection_at' do
66 it
'returns the connection that links to a vertex' do
67 e
.connections
.should be_empty
70 e
.connection_at(v1
).end.should be v1
71 e
.connection_at(v2
).end.should be v2
74 it
'returns nil if there is no connection to that vertex' do
75 e
.connections
.should be_empty
78 e
.connection_at(v3
).should be
nil
81 it
'returns the vertex for a self-loop' do
82 e
.connections
.should be_empty
85 e
.connection_at(v1
).end.should be v1
89 describe
'other_end' do
90 it
'returns the vertex at the other end of the given one' do
91 e
.connections
.should be_empty
94 e
.other_end(v1
).should be v2
95 e
.other_end(v2
).should be v1
98 it
'returns the same vertex in a self-loop' do
99 e
.connections
.should be_empty
102 e
.other_end(v1
).should be v1
105 it
'returns one of the connected edges if given a vertex not connected to it' do
106 e
.connections
.should be_empty
109 [v1
, v2
].should
include e
.other_end(v3
)
112 it
'returns nil if it cannot return something sensible' do
113 e
.other_end(v1
).should be_nil
115 e
.other_end(v1
).should be_nil
119 describe
'#to_dot' do
120 it
'describes an edge in dot notation' do
122 e
.to_dot
.should
== "#{v1.object_id.to_s} -- #{v2.object_id.to_s};"
125 it
'describes an edge in dot notation, using given attributes' do
128 edot
= e
.to_dot
:label => :name
129 edot
.should
== "#{v1.object_id.to_s} -- #{v2.object_id.to_s} {label = \"#{e.name}\"};"
132 it
'describes an edge in dot notation, given a block' do
134 e
.to_dot
{|e
| e
.object_id
.to_s
}.should
== e
.object_id
.to_s
139 describe Connection
do
140 let (:c) {Connection
.new
}
142 describe
'adds attribues' do
143 it
'adds then reports arbitrary attributes' do
147 end # adds attributes