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
"returns the string form of an edge" do
34 v1
= Vertex
.new
:name => :v1
35 v2
= Vertex
.new
:name => :v2
38 e
.to_s
.should
== '<E: test [<V: v1>, <V: v2>] >'
43 it
"adds a new vertex to an edge (with a connection)" do
44 e
.connections
.should be_empty
46 e
.should
have(1).connections
47 e
.should
have(1).vertices
48 e
.vertices
.should
include(v1
)
49 v1
.edges
.should
include(e
)
51 e
.should
have(2).connections
52 e
.should
have(2).vertices
53 e
.vertices
.should
include(v1
)
54 e
.vertices
.should
include(v2
)
55 v2
.edges
.should
include(e
)
58 it
'adds several vertices to an edge' do
59 e
.connections
.should be_empty
61 e
.vertices
.should
include(v1
)
62 e
.vertices
.should
include(v2
)
63 e
.should
have(2).vertices
66 it
'adds a self-loop' do
67 e
.connections
.should be_empty
69 e
.vertices
.should
include(v1
)
70 e
.should
have(2).vertices
71 e
.vertices
.uniq
.length
.should
== 1
75 describe
'connection_at' do
76 it
'returns the connection that links to a vertex' do
77 e
.connections
.should be_empty
80 e
.connection_at(v1
).end.should be v1
81 e
.connection_at(v2
).end.should be v2
84 it
'returns nil if there is no connection to that vertex' do
85 e
.connections
.should be_empty
88 e
.connection_at(v3
).should be
nil
91 it
'returns the vertex for a self-loop' do
92 e
.connections
.should be_empty
95 e
.connection_at(v1
).end.should be v1
99 describe
'other_end' do
100 it
'returns the vertex at the other end of the given one' do
101 e
.connections
.should be_empty
104 e
.other_end(v1
).should be v2
105 e
.other_end(v2
).should be v1
108 it
'returns the same vertex in a self-loop' do
109 e
.connections
.should be_empty
112 e
.other_end(v1
).should be v1
115 it
'returns one of the connected edges if given a vertex not connected to it' do
116 e
.connections
.should be_empty
119 [v1
, v2
].should
include e
.other_end(v3
)
122 it
'returns nil if it cannot return something sensible' do
123 e
.other_end(v1
).should be_nil
125 e
.other_end(v1
).should be_nil
129 describe
'#to_dot' do
130 it
'describes an edge in dot notation' do
132 e
.to_dot
.should
== "#{v1.object_id.to_s} -- #{v2.object_id.to_s};"
135 it
'describes an edge in dot notation, using given attributes' do
138 edot
= e
.to_dot
:label => :name
139 edot
.should
== "#{v1.object_id.to_s} -- #{v2.object_id.to_s} {label = \"#{e.name}\"};"
142 it
'describes an edge in dot notation, given a block' do
144 e
.to_dot
{|e
| e
.object_id
.to_s
}.should
== e
.object_id
.to_s
149 describe Connection
do
150 let (:c) {Connection
.new
}
152 describe
'adds attribues' do
153 it
'adds then reports arbitrary attributes' do
157 end # adds attributes