graph.njae 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/graph.njae.gemspec +1 -1
- data/lib/graph.njae/vertex.rb +6 -4
- data/spec/graph/vertex_spec.rb +125 -0
- metadata +12 -12
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/graph.njae.gemspec
CHANGED
data/lib/graph.njae/vertex.rb
CHANGED
@@ -31,10 +31,12 @@ module GraphNjae
|
|
31
31
|
|
32
32
|
# Return the set of neighbouring vertices
|
33
33
|
def neighbours
|
34
|
-
vertices = self.edges.map {|e| e.vertices}.flatten
|
35
|
-
vertices_to_me = vertices.select {|v| v == self}
|
36
|
-
other_vertices = vertices.select {|v| v != self}
|
37
|
-
(vertices_to_me[1..-1] || []) + other_vertices
|
34
|
+
#vertices = self.edges.map {|e| e.vertices}.flatten
|
35
|
+
#vertices_to_me = vertices.select {|v| v == self}
|
36
|
+
#other_vertices = vertices.select {|v| v != self}
|
37
|
+
#(vertices_to_me[1..-1] || []) + other_vertices#
|
38
|
+
self.edges.map {|e| e.vertices.take_while {|v| v != self} +
|
39
|
+
e.vertices.drop_while {|v| v != self}[1..-1]}.flatten
|
38
40
|
end
|
39
41
|
|
40
42
|
end
|
data/spec/graph/vertex_spec.rb
CHANGED
@@ -97,5 +97,130 @@ module GraphNjae
|
|
97
97
|
end
|
98
98
|
|
99
99
|
end # #connect
|
100
|
+
|
101
|
+
describe "#neighbours" do
|
102
|
+
it "finds neighbours of a self loop" do
|
103
|
+
v << v
|
104
|
+
v.should have(1).neighbours
|
105
|
+
v.neighbours.should include v
|
106
|
+
end
|
107
|
+
|
108
|
+
it "finds neighbours on an edge" do
|
109
|
+
v1 = Vertex.new
|
110
|
+
v << v1
|
111
|
+
v.should have(1).neighbours
|
112
|
+
v.neighbours.should include v1
|
113
|
+
v1.should have(1).neighbours
|
114
|
+
v1.neighbours.should include v
|
115
|
+
end
|
116
|
+
|
117
|
+
it "finds neighbours with multiple edges" do
|
118
|
+
v1 = Vertex.new
|
119
|
+
v1.id = :v1
|
120
|
+
v << v1
|
121
|
+
v1 << v
|
122
|
+
v.should have(2).neighbours
|
123
|
+
v.neighbours.should include v1
|
124
|
+
v.neighbours.should_not include v
|
125
|
+
v1.should have(2).neighbours
|
126
|
+
v1.neighbours.should include v
|
127
|
+
v1.neighbours.should_not include v1
|
128
|
+
end
|
129
|
+
|
130
|
+
it "finds neighbours with multiple self loops" do
|
131
|
+
v << v << v << v
|
132
|
+
v.should have(3).neighbours
|
133
|
+
v.neighbours.should include v
|
134
|
+
v.neighbours.uniq.length.should == 1
|
135
|
+
end
|
136
|
+
|
137
|
+
it "finds neighbours with all sorts of edges" do
|
138
|
+
v1 = Vertex.new ; v1.id = :v1
|
139
|
+
v2 = Vertex.new ; v2.id = :v2
|
140
|
+
v3 = Vertex.new ; v3.id = :v3
|
141
|
+
v1 << v
|
142
|
+
v << v2
|
143
|
+
v2 << v3
|
144
|
+
v2 << v2
|
145
|
+
|
146
|
+
v.should have(2).neighbours
|
147
|
+
v.neighbours.should include v1
|
148
|
+
v.neighbours.should include v2
|
149
|
+
|
150
|
+
v1.should have(1).neighbours
|
151
|
+
v1.neighbours.should include v
|
152
|
+
|
153
|
+
v2.should have(3).neighbours
|
154
|
+
v2.neighbours.should include v
|
155
|
+
v2.neighbours.should include v2
|
156
|
+
v2.neighbours.should include v3
|
157
|
+
|
158
|
+
v3.should have(1).neighbours
|
159
|
+
v3.neighbours.should include v2
|
160
|
+
end
|
161
|
+
|
162
|
+
it "finds neighbours in graphs with several vertices" do
|
163
|
+
v1 = Vertex.new ; v1.id = :v1
|
164
|
+
v2 = Vertex.new ; v2.id = :v2
|
165
|
+
v3 = Vertex.new ; v3.id = :v3
|
166
|
+
v4 = Vertex.new ; v4.id = :v4
|
167
|
+
v << v1
|
168
|
+
v1 << v2
|
169
|
+
v2 << v3
|
170
|
+
v << v3
|
171
|
+
v4 << v3
|
172
|
+
v.should have(2).neighbours
|
173
|
+
v.neighbours.should include v1
|
174
|
+
v.neighbours.should include v3
|
175
|
+
v.neighbours.should_not include v
|
176
|
+
v1.should have(2).neighbours
|
177
|
+
v1.neighbours.should include v
|
178
|
+
v1.neighbours.should include v2
|
179
|
+
v1.neighbours.should_not include v1
|
180
|
+
v2.should have(2).neighbours
|
181
|
+
v2.neighbours.should include v1
|
182
|
+
v2.neighbours.should include v3
|
183
|
+
v2.neighbours.should_not include v2
|
184
|
+
v3.should have(3).neighbours
|
185
|
+
v3.neighbours.should include v
|
186
|
+
v3.neighbours.should include v2
|
187
|
+
v3.neighbours.should include v4
|
188
|
+
v3.neighbours.should_not include v3
|
189
|
+
v4.should have(1).neighbours
|
190
|
+
v4.neighbours.should include v3
|
191
|
+
v4.neighbours.should_not include v4
|
192
|
+
end
|
193
|
+
|
194
|
+
it "finds neighbours with multiple edges between vertices" do
|
195
|
+
v1 = Vertex.new ; v1.id = :v1
|
196
|
+
v2 = Vertex.new ; v2.id = :v2
|
197
|
+
v3 = Vertex.new ; v3.id = :v3
|
198
|
+
v1 << v1 << v
|
199
|
+
v << v2
|
200
|
+
v << v
|
201
|
+
v3 << v2
|
202
|
+
v2 << v3
|
203
|
+
v2 << v2
|
204
|
+
|
205
|
+
v.should have(3).neighbours
|
206
|
+
v.neighbours.should include v1
|
207
|
+
v.neighbours.should include v2
|
208
|
+
v.neighbours.should include v
|
209
|
+
|
210
|
+
v1.should have(2).neighbours
|
211
|
+
v1.neighbours.should include v
|
212
|
+
v1.neighbours.should include v1
|
213
|
+
|
214
|
+
v2.should have(4).neighbours
|
215
|
+
v2.neighbours.should include v
|
216
|
+
v2.neighbours.should include v2
|
217
|
+
v2.neighbours.should include v3
|
218
|
+
v2.neighbours.uniq.length.should == 3
|
219
|
+
|
220
|
+
v3.should have(2).neighbours
|
221
|
+
v3.neighbours.should include v2
|
222
|
+
v3.neighbours.uniq.length.should == 1
|
223
|
+
end
|
224
|
+
end # #neighbours
|
100
225
|
end
|
101
226
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graph.njae
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-26 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &78709830 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.6.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *78709830
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &78708940 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *78708940
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &78707840 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.6.2
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *78707840
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rcov
|
49
|
-
requirement: &
|
49
|
+
requirement: &78707190 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *78707190
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rdoc
|
60
|
-
requirement: &
|
60
|
+
requirement: &78706180 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *78706180
|
69
69
|
description: A simple graph library
|
70
70
|
email: neil.github@njae.me.uk
|
71
71
|
executables: []
|
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
segments:
|
108
108
|
- 0
|
109
|
-
hash:
|
109
|
+
hash: 550646159
|
110
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
111
|
none: false
|
112
112
|
requirements:
|