f4be16b5e3787353e08e5261133d47f83cc06edb
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
"returns the string form of an edge" do
30 v1
= Vertex
.new
:name => :v1
31 v2
= Vertex
.new
:name => :v2
34 e
.to_s
.should
== '<E: test [<V: v1>, <V: v2>] >'
39 it
"adds a new vertex to an edge (with a connection)" do
40 e
.connections
.should be_empty
41 v1
= Vertex
.new
:name => :v1
42 v2
= Vertex
.new
:name => :v2
44 e
.should
have(1).connections
45 e
.should
have(1).vertices
46 e
.vertices
.should
include(v1
)
47 v1
.edges
.should
include(e
)
49 e
.should
have(2).connections
50 e
.should
have(2).vertices
51 e
.vertices
.should
include(v1
)
52 e
.vertices
.should
include(v2
)
53 v2
.edges
.should
include(e
)
56 it
"adds several vertices to an edge" do
57 e
.connections
.should be_empty
58 v1
= Vertex
.new
:name => :v1
59 v2
= Vertex
.new
:name => :v2
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
70 e
.vertices
.should
include(v1
)
71 e
.should
have(2).vertices
72 e
.vertices
.uniq
.length
.should
== 1
76 describe
"connection_at" do
77 it
"returns the connection that links to a vertex" do
78 e
.connections
.should be_empty
79 v1
= Vertex
.new
:name => :v1
80 v2
= Vertex
.new
:name => :v2
83 e
.connection_at(v1
).end.should be v1
84 e
.connection_at(v2
).end.should be v2
87 it
"returns nil if there is no connection to that vertex" do
88 e
.connections
.should be_empty
89 v1
= Vertex
.new
:name => :v1
90 v2
= Vertex
.new
:name => :v2
91 v3
= Vertex
.new
:name => :v3
94 e
.connection_at(v3
).should be
nil
97 it
"returns the vertex for a self-loop" do
98 e
.connections
.should be_empty
99 v1
= Vertex
.new
:name => :v1
102 e
.connection_at(v1
).end.should be v1
106 describe
"other_end" do
107 it
"returns the vertex at the other end of the given one" do
108 e
.connections
.should be_empty
109 v1
= Vertex
.new
:name => :v1
110 v2
= Vertex
.new
:name => :v2
113 e
.other_end(v1
).should be v2
114 e
.other_end(v2
).should be v1
117 it
"returns the same vertex in a self-loop" do
118 e
.connections
.should be_empty
119 v1
= Vertex
.new
:name => :v1
122 e
.other_end(v1
).should be v1
125 it
"returns one of the connected edges if given a vertex not connected to it" do
126 e
.connections
.should be_empty
127 v1
= Vertex
.new
:name => :v1
128 v2
= Vertex
.new
:name => :v2
129 v3
= Vertex
.new
:name => :v3
132 [v1
, v2
].should
include e
.other_end(v3
)
135 it
"returns nil if it can't return something sensible" do
136 v1
= Vertex
.new
:name => :v1
137 e
.other_end(v1
).should be_nil
139 e
.other_end(v1
).should be_nil
144 describe Connection
do
145 let (:c) {Connection
.new
}
147 describe
"adds attribues" do
148 it
"adds then reports arbitrary attributes" do
152 end # adds attributes