1 require File
.expand_path(File
.dirname(__FILE__
) + '/../spec_helper')
6 describe
"#initialize" do
7 it
"creates an empty edge" do
9 e
.connections
.should be_empty
12 it
"creates an edge with some parameters" do
13 e
= Edge
.new
:value1 => 1, :value2 => "value2", :value3 => :v3
15 e
.value2
.should
== "value2"
16 e
.value3
.should
== :v3
17 e
.value4
.should be_nil
21 describe
"adds attribues" do
22 it
"adds then reports arbitrary attributes" do
29 it
"adds a new vertex to an edge (with a connection)" do
30 e
.connections
.should be_empty
31 v1
= Vertex
.new
:name => :v1
32 v2
= Vertex
.new
:name => :v2
34 e
.should
have(1).connections
35 e
.should
have(1).vertices
36 e
.vertices
.should
include(v1
)
37 v1
.edges
.should
include(e
)
39 e
.should
have(2).connections
40 e
.should
have(2).vertices
41 e
.vertices
.should
include(v1
)
42 e
.vertices
.should
include(v2
)
43 v2
.edges
.should
include(e
)
46 it
"adds several vertices to an edge" do
47 e
.connections
.should be_empty
48 v1
= Vertex
.new
:name => :v1
49 v2
= Vertex
.new
:name => :v2
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
60 e
.vertices
.should
include(v1
)
61 e
.should
have(2).vertices
62 e
.vertices
.uniq
.length
.should
== 1
66 describe
"connection_at" do
67 it
"returns the connection that links to a vertex" do
68 e
.connections
.should be_empty
69 v1
= Vertex
.new
:name => :v1
70 v2
= Vertex
.new
:name => :v2
73 e
.connection_at(v1
).end.should be v1
74 e
.connection_at(v2
).end.should be v2
77 it
"returns nil if there is no connection to that vertex" do
78 e
.connections
.should be_empty
79 v1
= Vertex
.new
:name => :v1
80 v2
= Vertex
.new
:name => :v2
81 v3
= Vertex
.new
:name => :v3
84 e
.connection_at(v3
).should be
nil
87 it
"returns the vertex for a self-loop" do
88 e
.connections
.should be_empty
89 v1
= Vertex
.new
:name => :v1
92 e
.connection_at(v1
).end.should be v1
96 describe
"other_end" do
97 it
"returns the vertex at the other end of the given one" do
98 e
.connections
.should be_empty
99 v1
= Vertex
.new
:name => :v1
100 v2
= Vertex
.new
:name => :v2
103 e
.other_end(v1
).should be v2
104 e
.other_end(v2
).should be v1
107 it
"returns the same vertex in a self-loop" do
108 e
.connections
.should be_empty
109 v1
= Vertex
.new
:name => :v1
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
117 v1
= Vertex
.new
:name => :v1
118 v2
= Vertex
.new
:name => :v2
119 v3
= Vertex
.new
:name => :v3
122 [v1
, v2
].should
include e
.other_end(v3
)
125 it
"returns nil if it can't return something sensible" do
126 v1
= Vertex
.new
:name => :v1
127 e
.other_end(v1
).should be_nil
129 e
.other_end(v1
).should be_nil
134 describe Connection
do
135 let (:c) {Connection
.new
}
137 describe
"adds attribues" do
138 it
"adds then reports arbitrary attributes" do
142 end # adds attributes