jumoku 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/Gemfile +4 -0
  2. data/lib/jumoku.rb +4 -2
  3. data/lib/jumoku/version.rb +1 -1
  4. data/spec/raw_tree_spec.rb +353 -0
  5. data/spec/spec.opts +4 -0
  6. data/spec/spec_helper.rb +14 -0
  7. data/spec/tree_spec.rb +553 -0
  8. data/vendor/git/graphy/CREDITS.md +31 -0
  9. data/vendor/git/graphy/LICENSE +35 -0
  10. data/vendor/git/graphy/README.md +186 -0
  11. data/vendor/git/graphy/Rakefile +61 -0
  12. data/vendor/git/graphy/TODO.md +20 -0
  13. data/vendor/git/graphy/VERSION +1 -0
  14. data/vendor/git/graphy/examples/graph_self.rb +56 -0
  15. data/vendor/git/graphy/examples/module_graph.jpg +0 -0
  16. data/vendor/git/graphy/examples/module_graph.rb +14 -0
  17. data/vendor/git/graphy/examples/self_graph.jpg +0 -0
  18. data/vendor/git/graphy/examples/visualize.jpg +0 -0
  19. data/vendor/git/graphy/examples/visualize.rb +10 -0
  20. data/vendor/git/graphy/graphy.gemspec +149 -0
  21. data/vendor/git/graphy/lib/graphy.rb +90 -0
  22. data/vendor/git/graphy/lib/graphy/adjacency_graph.rb +224 -0
  23. data/vendor/git/graphy/lib/graphy/arc.rb +65 -0
  24. data/vendor/git/graphy/lib/graphy/arc_number.rb +52 -0
  25. data/vendor/git/graphy/lib/graphy/biconnected.rb +84 -0
  26. data/vendor/git/graphy/lib/graphy/chinese_postman.rb +91 -0
  27. data/vendor/git/graphy/lib/graphy/classes/graph_classes.rb +28 -0
  28. data/vendor/git/graphy/lib/graphy/common.rb +63 -0
  29. data/vendor/git/graphy/lib/graphy/comparability.rb +63 -0
  30. data/vendor/git/graphy/lib/graphy/directed_graph.rb +76 -0
  31. data/vendor/git/graphy/lib/graphy/directed_graph/algorithms.rb +92 -0
  32. data/vendor/git/graphy/lib/graphy/directed_graph/distance.rb +167 -0
  33. data/vendor/git/graphy/lib/graphy/dot.rb +94 -0
  34. data/vendor/git/graphy/lib/graphy/edge.rb +37 -0
  35. data/vendor/git/graphy/lib/graphy/ext.rb +79 -0
  36. data/vendor/git/graphy/lib/graphy/graph.rb +631 -0
  37. data/vendor/git/graphy/lib/graphy/graph_api.rb +35 -0
  38. data/vendor/git/graphy/lib/graphy/labels.rb +113 -0
  39. data/vendor/git/graphy/lib/graphy/maximum_flow.rb +77 -0
  40. data/vendor/git/graphy/lib/graphy/ruby_compatibility.rb +17 -0
  41. data/vendor/git/graphy/lib/graphy/search.rb +511 -0
  42. data/vendor/git/graphy/lib/graphy/strong_components.rb +93 -0
  43. data/vendor/git/graphy/lib/graphy/support/support.rb +9 -0
  44. data/vendor/git/graphy/lib/graphy/undirected_graph.rb +57 -0
  45. data/vendor/git/graphy/lib/graphy/undirected_graph/algorithms.rb +90 -0
  46. data/vendor/git/graphy/spec/biconnected_spec.rb +27 -0
  47. data/vendor/git/graphy/spec/chinese_postman_spec.rb +27 -0
  48. data/vendor/git/graphy/spec/community_spec.rb +44 -0
  49. data/vendor/git/graphy/spec/complement_spec.rb +27 -0
  50. data/vendor/git/graphy/spec/digraph_distance_spec.rb +121 -0
  51. data/vendor/git/graphy/spec/digraph_spec.rb +339 -0
  52. data/vendor/git/graphy/spec/dot_spec.rb +48 -0
  53. data/vendor/git/graphy/spec/edge_spec.rb +159 -0
  54. data/vendor/git/graphy/spec/inspection_spec.rb +40 -0
  55. data/vendor/git/graphy/spec/multi_edge_spec.rb +32 -0
  56. data/vendor/git/graphy/spec/neighborhood_spec.rb +38 -0
  57. data/vendor/git/graphy/spec/properties_spec.rb +146 -0
  58. data/vendor/git/graphy/spec/search_spec.rb +227 -0
  59. data/vendor/git/graphy/spec/spec.opts +4 -0
  60. data/vendor/git/graphy/spec/spec_helper.rb +56 -0
  61. data/vendor/git/graphy/spec/strong_components_spec.rb +61 -0
  62. data/vendor/git/graphy/spec/triangulated_spec.rb +125 -0
  63. data/vendor/git/graphy/spec/undirected_graph_spec.rb +220 -0
  64. data/vendor/git/graphy/vendor/priority-queue/CHANGELOG +33 -0
  65. data/vendor/git/graphy/vendor/priority-queue/Makefile +140 -0
  66. data/vendor/git/graphy/vendor/priority-queue/README +133 -0
  67. data/vendor/git/graphy/vendor/priority-queue/benchmark/dijkstra.rb +171 -0
  68. data/vendor/git/graphy/vendor/priority-queue/compare_comments.rb +49 -0
  69. data/vendor/git/graphy/vendor/priority-queue/doc/c-vs-rb.png +0 -0
  70. data/vendor/git/graphy/vendor/priority-queue/doc/compare_big.gp +14 -0
  71. data/vendor/git/graphy/vendor/priority-queue/doc/compare_big.png +0 -0
  72. data/vendor/git/graphy/vendor/priority-queue/doc/compare_small.gp +15 -0
  73. data/vendor/git/graphy/vendor/priority-queue/doc/compare_small.png +0 -0
  74. data/vendor/git/graphy/vendor/priority-queue/doc/results.csv +37 -0
  75. data/vendor/git/graphy/vendor/priority-queue/ext/priority_queue/CPriorityQueue/extconf.rb +2 -0
  76. data/vendor/git/graphy/vendor/priority-queue/ext/priority_queue/CPriorityQueue/priority_queue.c +947 -0
  77. data/vendor/git/graphy/vendor/priority-queue/lib/priority_queue.rb +14 -0
  78. data/vendor/git/graphy/vendor/priority-queue/lib/priority_queue/c_priority_queue.rb +1 -0
  79. data/vendor/git/graphy/vendor/priority-queue/lib/priority_queue/poor_priority_queue.rb +46 -0
  80. data/vendor/git/graphy/vendor/priority-queue/lib/priority_queue/ruby_priority_queue.rb +526 -0
  81. data/vendor/git/graphy/vendor/priority-queue/priority_queue.so +0 -0
  82. data/vendor/git/graphy/vendor/priority-queue/setup.rb +1551 -0
  83. data/vendor/git/graphy/vendor/priority-queue/test/priority_queue_test.rb +371 -0
  84. data/vendor/git/graphy/vendor/rdot.rb +360 -0
  85. metadata +83 -1
@@ -0,0 +1,339 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe "Digraph" do # :nodoc:
4
+
5
+ before do
6
+ @single = Digraph[1,2, 2,3, 3,4, 1,2, 2,3, 4,4]
7
+ @dups = DirectedPseudoGraph[1,2, 2,3, 3,4, 1,2, 2,3, 4,4]
8
+ @loops = DirectedMultiGraph[1,2, 2,3, 3,4, 4,4, 1,2, 2,3]
9
+ end
10
+
11
+ describe "new" do
12
+ it do
13
+ @single.should == Digraph[1,2, 2,3, 3,4]
14
+ @dups.should == DirectedPseudoGraph.new([1,2, 2,3, 3,4, 1,2, 2,3])
15
+ @loops.should == DirectedMultiGraph.new([1,2, 2,3, 3,4, 4,4, 1,2, 2,3])
16
+ proc { Digraph.new(:loops) }.should raise_error(ArgumentError)
17
+ proc { Digraph.new(:parallel_edges) }.should raise_error(ArgumentError)
18
+ proc { DirectedMultiGraph.new(:loops) }.should raise_error(ArgumentError)
19
+ proc { DirectedMultiGraph.new(:parallel_edges) }.should raise_error(ArgumentError)
20
+ proc { DirectedPseudoGraph.new(:loops) }.should raise_error(ArgumentError)
21
+ proc { DirectedPseudoGraph.new(:parallel_edges) }.should raise_error(ArgumentError)
22
+ proc { Digraph.new(1) }.should raise_error(ArgumentError)
23
+ Digraph.new(@single).should == @single
24
+ DirectedPseudoGraph.new(@dups).should == @dups
25
+ DirectedMultiGraph.new(@loops).should == @loops
26
+ Digraph.new(@loops).should == Digraph[1,2, 2,3, 3,4]
27
+ end
28
+ end
29
+
30
+ describe "edges" do
31
+ it do
32
+ @single.edges.size.should == 3
33
+ @single.edges.include?(Arc[1,2]).should be_true
34
+ @single.edges.include?(Arc[2,3]).should be_true
35
+ @single.edges.include?(Arc[3,4]).should be_true
36
+ @single.edges.include?(Arc[4,4]).should be_false
37
+ @single.edges.include?(Arc[1,2]).should be_true
38
+ @single.edges.include?(Arc[2,3]).should be_true
39
+ @single.edges.include?(Arc[1,3]).should be_false
40
+ @single.edge?(2,3).should be_true
41
+ @single.edge?(1,4).should be_false
42
+ @single.edge?(Arc[1,2]).should be_true
43
+ @single.add_edge!(5,5).edge?(5,5).should be_false
44
+ @single.remove_edge!(5,5).edge?(5,5).should be_false
45
+
46
+ @dups.edges.size.should == 5
47
+ @dups.edges.include?(MultiArc[1,2]).should be_true
48
+ @dups.edges.include?(MultiArc[2,3]).should be_true
49
+ @dups.edges.include?(MultiArc[3,4]).should be_true
50
+ @dups.edges.include?(MultiArc[4,4]).should be_false
51
+ @dups.edges.include?(MultiArc[1,2]).should be_true
52
+ @dups.edges.include?(MultiArc[2,3]).should be_true
53
+ @dups.edges.include?(MultiArc[1,3]).should be_false
54
+ @dups.edge?(2,3).should be_true
55
+ @dups.edge?(1,4).should be_false
56
+ @dups.edge?(MultiArc[1,2]).should be_true
57
+ @dups.add_edge!(5,5).edge?(5,5).should be_false
58
+ proc { @dups.remove_edge!(5,5) }.should raise_error(ArgumentError)
59
+
60
+ @dups.edges.size.should == 5
61
+ @loops.edges.include?(MultiArc[1,2]).should be_true
62
+ @loops.edges.include?(MultiArc[2,3]).should be_true
63
+ @loops.edges.include?(MultiArc[3,4]).should be_true
64
+ @loops.edges.include?(MultiArc[4,4]).should be_true
65
+ @loops.edges.include?(MultiArc[1,2]).should be_true
66
+ @loops.edges.include?(MultiArc[2,3]).should be_true
67
+ @loops.edges.include?(MultiArc[1,3]).should be_false
68
+ @loops.edge?(2,3).should be_true
69
+ @loops.edge?(1,4).should be_false
70
+ @loops.edge?(MultiArc[1,2]).should be_true
71
+ @loops.add_edge!(5,5).edge?(5,5).should be_true
72
+ proc { @loops.remove_edge!(5,5) }.should raise_error(ArgumentError)
73
+ end
74
+
75
+ end
76
+
77
+ describe "vertices" do
78
+ it do
79
+ @single.vertices.sort.should == [1,2,3,4]
80
+ @single.add_vertex!(5).to_a.sort.should == [1,2,3,4,5]
81
+ @single.remove_vertex!(3).to_a.sort.should == [1,2,4,5]
82
+ @single.vertex?(3).should be_false
83
+ @single.edge?(2,3).should be_false
84
+ @single.edge?(3,4).should be_false
85
+ @single.add_vertex(:bogus).vertex?(:bogus).should be_true
86
+ @single.add_vertex(:bogus).vertex?(nil).should be_false
87
+ @single.vertex?(:bogus).should be_false
88
+ @single.add_vertex!(:real)
89
+ @single.vertex?(:real).should be_true
90
+ @single.add_edge(:here, :there).edge?(Arc[:here, :there]).should be_true
91
+ @single.edge?(Arc[:here, :there]).should be_false
92
+ @single.vertex?(:here).should be_false
93
+ @single.vertex?(:there).should be_false
94
+ @single.add_edge!(:here, :there)
95
+ @single.edge?(Arc[:here, :there]).should be_true
96
+ @single.vertex?(:here).should be_true
97
+ @single.vertex?(:there).should be_true
98
+ end
99
+ end
100
+
101
+ describe "properties" do
102
+ it do
103
+ @single.should be_directed
104
+ @single.should_not be_empty
105
+ Digraph.new.should be_empty
106
+ @single.size.should == 4
107
+ @dups.size.should == 4
108
+ @loops.size.should == 4
109
+ @single.num_vertices.should == 4
110
+ @dups.num_vertices.should == 4
111
+ @single.num_edges.should == 3
112
+ @dups.num_edges.should == 5
113
+ @loops.num_edges.should == 6
114
+ @single.should be_oriented
115
+ @single.remove_vertex!(4)
116
+ @single.should be_oriented
117
+ @loops.oriented?.should be_false
118
+ @loops.remove_vertex!(4)
119
+ @loops.should be_oriented
120
+ end
121
+ end
122
+
123
+ describe "merge" do
124
+ it do
125
+ @dups.merge(@single)
126
+ @dups.num_edges.should == 8
127
+ @dups.vertices.sort.should == [1,2,3,4]
128
+ end
129
+ end
130
+
131
+ describe "operators" do
132
+ it do
133
+ result = @single + Arc[3,2]
134
+ @single.size.should == 4
135
+ @single.num_edges.should == 3
136
+ result.size.should == 4
137
+ result.num_edges.should == 4
138
+
139
+ result = @single + 5
140
+ @single.size.should == 4
141
+ @single.num_edges.should == 3
142
+ result.size.should == 5
143
+ result.num_edges.should == 3
144
+
145
+ result = @single - Arc[4,4]
146
+ @single.size.should == 4
147
+ @single.num_edges.should == 3
148
+ result.size.should == 4
149
+ result.num_edges.should == 3
150
+
151
+ e = @loops.edges.detect { |e| e.source == 4 && e.target == 4 }
152
+ result = @loops - e
153
+ @single.size.should == 4
154
+ @single.num_edges.should == 3
155
+ result.size.should == 4
156
+ result.num_edges.should == 5
157
+
158
+ result = @single - 4
159
+ @single.size.should == 4
160
+ @single.num_edges.should == 3
161
+ result.size.should == 3
162
+ result.num_edges.should == 2
163
+
164
+ @single << Arc[6,1]
165
+ @single.size.should == 5
166
+ @single.num_edges.should == 4
167
+ @single.edge?(6,1).should be_true
168
+ end
169
+ end
170
+
171
+ describe "reversal" do
172
+ it do
173
+ reverse = @single.add_vertex!(42).reversal
174
+ reverse.vertices.sort.should == [1,2,3,4,42]
175
+ reverse.edge?(2,1).should be_true
176
+ reverse.edge?(3,2).should be_true
177
+ reverse.edge?(4,3).should be_true
178
+ reverse.edge?(4,4).should be_false
179
+ reverse.num_edges.should == 3
180
+ reverse = @loops.reversal
181
+ reverse.edge?(4,4).should be_true
182
+ end
183
+ end
184
+
185
+ describe "complement" do
186
+ it do
187
+ complement = @single.complement
188
+ complement.vertices.sort.should == [1,2,3,4]
189
+ complement.edge?(1,1).should be_false
190
+ complement.edge?(1,3).should be_true
191
+ complement.edge?(1,4).should be_true
192
+ complement.edge?(2,1).should be_true
193
+ complement.edge?(2,4).should be_true
194
+ complement.edge?(3,1).should be_true
195
+ complement.edge?(3,2).should be_true
196
+ complement.edge?(4,1).should be_true
197
+ complement.edge?(4,2).should be_true
198
+ complement.edge?(4,3).should be_true
199
+ complement.num_edges.should == 9
200
+
201
+ complement = @loops.complement
202
+ complement.vertices.sort.should == [1,2,3,4]
203
+ complement.edge?(1,1).should be_true
204
+ complement.edge?(1,3).should be_true
205
+ complement.edge?(1,4).should be_true
206
+ complement.edge?(2,1).should be_true
207
+ complement.edge?(2,2).should be_true
208
+ complement.edge?(2,4).should be_true
209
+ complement.edge?(3,1).should be_true
210
+ complement.edge?(3,2).should be_true
211
+ complement.edge?(3,3).should be_true
212
+ complement.edge?(4,1).should be_true
213
+ complement.edge?(4,2).should be_true
214
+ complement.edge?(4,3).should be_true
215
+ complement.num_edges.should == 12
216
+ end
217
+ end
218
+
219
+ describe "induced_subgraph" do
220
+ it do
221
+ induced = @single.induced_subgraph([1,2])
222
+ induced.vertices.sort.should == [1,2]
223
+ induced.edge?(1,2).should be_true
224
+ induced.num_edges.should == 1
225
+ end
226
+ end
227
+
228
+ describe "include" do
229
+ it do
230
+ @single.include?(4).should be_true
231
+ @dups.include?(4).should be_true
232
+ @dups.include?(5).should be_false
233
+ @single.include?(5).should be_false
234
+ @single.include?(Arc[1,2]).should be_true
235
+ @dups.include?(Arc[1,2]).should be_true
236
+ end
237
+ end
238
+
239
+ describe "adjacent" do
240
+ it do
241
+
242
+ @single.adjacent?(2, Arc[1,2]).should be_true
243
+ @single.adjacent(1).should == [2]
244
+
245
+ @single.adjacent(1, :type=>:edges).should == [Arc[1,2]]
246
+ @single.adjacent(1, :type=>:edges, :direction=> :out).should == [Arc[1,2]]
247
+ @single.adjacent(2, :type=>:edges, :direction=> :in).should == [Arc[1,2]]
248
+ @single.adjacent(2, :type=>:edges, :direction=> :all).sort.should == [Arc[1,2],Arc[2,3]]
249
+
250
+ [[{},1], [{:direction => :out},1], [{:direction => :in},2]].each do |h,v|
251
+ adj = @dups.adjacent(v, h.merge(:type=>:edges))
252
+ adj.size.should == 2
253
+ adj.each do |e|
254
+ e.source == 1; e.target.should == 2
255
+ end
256
+ end
257
+
258
+ adj = @dups.adjacent(2, {:type=>:edges,:direction=>:all})
259
+ adj.size.should == 4
260
+ adj.each do |e|
261
+ ((e.source==1 and e.target==2) ||
262
+ (e.source==2 and e.target==3)).should be_true
263
+ end
264
+
265
+ @single.adjacent(1, :type=>:vertices).should == [2]
266
+ @single.adjacent(1, :type=>:vertices, :direction=> :out).should == [2]
267
+ @single.adjacent(2, :type=>:vertices, :direction=> :in).should == [1]
268
+ @single.adjacent(2, :type=>:vertices, :direction=> :all).should == [1,3]
269
+
270
+ @single.adjacent(Arc[2,3], :type=>:vertices).should == [3]
271
+ @single.adjacent(Arc[2,3], :type=>:vertices, :direction=> :out).should == [3]
272
+ @single.adjacent(Arc[2,3], :type=>:vertices, :direction=> :in).should == [2]
273
+ @single.adjacent(Arc[2,3], :type=>:vertices, :direction=> :all).should == [2,3]
274
+
275
+ @single.adjacent(Arc[2,3], :type=>:edges).should == [Arc[3,4]]
276
+ @single.adjacent(Arc[2,3], :type=>:edges, :direction=> :out).should == [Arc[3,4]]
277
+ @single.adjacent(Arc[2,3], :type=>:edges, :direction=> :in).should == [Arc[1,2]]
278
+ @single.adjacent(Arc[2,3], :type=>:edges, :direction=> :all).sort.should == [Arc[1,2],Arc[3,4]]
279
+
280
+ @dups.adjacent(MultiArc[2,3], :type=>:edges).should == [MultiArc[3,4]]
281
+ @dups.adjacent(MultiArc[2,3], :type=>:edges, :direction=> :out).should == [MultiArc[3,4]]
282
+ @dups.adjacent(MultiArc[2,3], :type=>:edges, :direction=> :in).should == [MultiArc[1,2]]*2
283
+ @dups.adjacent(MultiArc[2,3], :type=>:edges, :direction=> :all).sort.should == ([MultiArc[1,2]]*2+[MultiArc[3,4]])
284
+ end
285
+
286
+ end
287
+
288
+ describe "neighborhood" do
289
+ it do
290
+ @single.neighborhood(1).sort.should == [2]
291
+ @single.neighborhood(2).sort.should == [1,3]
292
+ @single.neighborhood(Arc[2,3]).sort.should == [Arc[1,2], Arc[3,4]]
293
+ end
294
+ end
295
+
296
+ describe "degree" do
297
+ it do
298
+ @single.in_degree(1).should == 0
299
+ @single.in_degree(2).should == 1
300
+ @single.in_degree(4).should == 1
301
+ @loops.degree(4).should == 3
302
+ @loops.in_degree(4).should == 2
303
+ @single.out_degree(1).should == 1
304
+ @single.out_degree(2).should == 1
305
+ @single.out_degree(4).should == 0
306
+ @loops.out_degree(4).should == 1
307
+ @single.add_vertex!(6).out_degree(6).should == 0
308
+ @single.add_vertex!(7).in_degree(7).should == 0
309
+ @single.add_edge!(4,2).out_degree(4).should == 1
310
+ @loops.add_edge!(4,2).out_degree(4).should == 2
311
+ @single.in_degree(2).should == 2
312
+
313
+ @single.min_in_degree.should == 0
314
+ @single.max_in_degree.should == 2
315
+ @single.min_out_degree.should == 0
316
+ @single.max_out_degree.should == 1
317
+
318
+ @loops.min_in_degree.should == 0
319
+ @loops.max_in_degree.should == 2
320
+ @loops.min_out_degree.should == 1
321
+ @loops.max_out_degree.should == 2
322
+ @loops.degree(2).should == 4
323
+ @single.degree(1).should == 1
324
+ @loops.should_not be_regular
325
+ @single.should_not be_regular
326
+ @dups.should_not be_regular
327
+ end
328
+ end
329
+
330
+ describe "include" do
331
+ it do
332
+ @single.include?(2).should be_true
333
+ @single.include?(23).should be_false
334
+ @single.include?(Arc[1,2]).should be_true
335
+ @single.include?(Arc[1,4]).should be_false
336
+ end
337
+ end
338
+
339
+ end
@@ -0,0 +1,48 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe "Dot" do # :nodoc:
4
+
5
+ DG_DOT = <<-DOT
6
+ digraph {
7
+ label = "Datacenters"
8
+ Miranda [
9
+ color = green,
10
+ style = filled,
11
+ label = "Miranda"
12
+ ]
13
+
14
+ Miranda -> Hillview [
15
+
16
+ ]
17
+
18
+ Miranda -> "San Francisco" [
19
+
20
+ ]
21
+
22
+ Miranda -> "San Jose" [
23
+
24
+ ]
25
+
26
+ Sunnyvale -> Miranda [
27
+
28
+ ]
29
+
30
+ }
31
+ DOT
32
+
33
+ before do
34
+ @dg = DOT::DOTDigraph.new('label' => 'Datacenters')
35
+ @dg << DOT::DOTNode.new('name' => 'Miranda', 'color' => 'green', 'style' => 'filled')
36
+ @dg << DOT::DOTDirectedArc.new('from' => 'Miranda', 'to' => 'Hillview')
37
+ @dg << DOT::DOTDirectedArc.new('from' => 'Miranda', 'to' => '"San Francisco"')
38
+ @dg << DOT::DOTDirectedArc.new('from' => 'Miranda', 'to' => '"San Jose"')
39
+ @dg << DOT::DOTDirectedArc.new('from' => 'Sunnyvale', 'to' => 'Miranda')
40
+ end
41
+
42
+ describe "generation" do
43
+ it do
44
+ @dg.to_s.should == DG_DOT
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,159 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe "Arc" do # :nodoc:
4
+
5
+ before do
6
+ @e = Arc.new(1,2,'boo')
7
+ @u = Edge.new(1,2,'hoo')
8
+ end
9
+
10
+ describe "edge_new" do
11
+ it do
12
+ proc { Arc.new }.should raise_error(ArgumentError)
13
+ proc { Arc.new(1) }.should raise_error(ArgumentError)
14
+ Arc.new(1,2).should be_a_kind_of(Arc)
15
+ Arc.new(1,2,'label').should be_a_kind_of(Arc)
16
+ end
17
+ end
18
+
19
+ describe "edge_getters" do
20
+ it do
21
+ @e.source.should == 1
22
+ @e.target.should == 2
23
+ @e.label.should == 'boo'
24
+
25
+ @e[0].should == 1
26
+ @e[1].should == 2
27
+ @e[2].should == 'boo'
28
+
29
+ @e[-3].should == 1
30
+ @e[-2].should == 2
31
+ @e[-1].should == 'boo'
32
+
33
+ proc { @e[-4] }.should raise_error(IndexError)
34
+ proc { @e[3] }.should raise_error(IndexError)
35
+
36
+ @e['source'].should == 1
37
+ @e['target'].should == 2
38
+ @e['label'].should == 'boo'
39
+
40
+ @e[:source].should == 1
41
+ @e[:target].should == 2
42
+ @e[:label].should == 'boo'
43
+ end
44
+ end
45
+
46
+ describe "edge_setters" do
47
+ it do
48
+ @e.source = 23
49
+ @e.target = 42
50
+ @e.label = 'Yabba'
51
+ @e.source.should == 23
52
+ @e.target.should == 42
53
+ @e.label.should == 'Yabba'
54
+
55
+ @e['source'] = 2
56
+ @e['target'] = 1
57
+ @e['label'] = 'Dabba'
58
+ @e.source.should == 2
59
+ @e.target.should == 1
60
+ @e.label.should == 'Dabba'
61
+
62
+ @e[:source] = 9
63
+ @e[:target] = 8
64
+ @e['label'] = 'Doooo!'
65
+ @e.source.should == 9
66
+ @e.target.should == 8
67
+ @e.label.should == 'Doooo!'
68
+
69
+ @e[0] = 'Fred'
70
+ @e[1] = 'Flintstone'
71
+ @e[2] = 'and'
72
+ @e.source.should == 'Fred'
73
+ @e.target.should == 'Flintstone'
74
+ @e.label.should == 'and'
75
+
76
+ @e[-3] = 'Barney'
77
+ @e[-2] = 'Rubble'
78
+ @e[-1] = nil
79
+ @e.source.should == 'Barney'
80
+ @e.target.should == 'Rubble'
81
+ @e.label.should == nil
82
+ end
83
+ end
84
+
85
+ describe "edge_simple_methods" do
86
+ it do
87
+ @e.to_a.should == [1,2,'boo']
88
+ @e.to_s.should == "(1-2 'boo')"
89
+ @e.label = nil
90
+ @e.to_s.should == "(1-2)"
91
+ @e.eql?(Arc.new(1,2)).should be_true
92
+ @e.eql?(Arc.new(1,3)).should be_false
93
+ Arc.new(2,1).eql?(@e).should be_false
94
+
95
+ @e.should == Arc.new(1,2)
96
+ @e.reverse.should == Arc.new(2,1)
97
+ Arc.new(1,2).should_not == Arc.new(1,3)
98
+ Arc.new(2,1).should_not == @e
99
+ end
100
+ end
101
+
102
+ describe "edge_sort" do
103
+ it do
104
+ x = [ Arc.new(2,3), Arc.new(1,3), Arc.new(1,2), Arc.new(2,1) ].sort
105
+ x.should == [Arc.new(1,2), Arc.new(1,3), Arc.new(2,1), Arc.new(2,3)]
106
+ end
107
+ end
108
+
109
+ describe "undirected_edge_new" do
110
+ it do
111
+ proc { Edge.new }.should raise_error(ArgumentError)
112
+ proc { Edge.new(1) }.should raise_error(ArgumentError)
113
+ Edge.new(1,2).should be_a_kind_of(Edge)
114
+ Edge.new(1,2,'label').should be_a_kind_of(Edge)
115
+ end
116
+ end
117
+
118
+ describe "undirected_edge_getters" do
119
+ it do
120
+ @u.source.should == 1
121
+ @u.target.should == 2
122
+ @u.to_a.should == [1,2,'hoo']
123
+ @u.to_s.should == "(1=2 'hoo')"
124
+ end
125
+ end
126
+
127
+ describe "undirected_edge_methods" do
128
+ it do
129
+ @u.label = nil
130
+ @u.to_s.should == "(1=2)"
131
+ Edge.new(2,1).to_s.should == "(1=2)"
132
+
133
+ @u.should == Edge.new(2,1)
134
+ @u.should == Edge.new(2,1,'boo')
135
+ @u.should_not == Edge.new(2,3)
136
+
137
+ Edge.new(2,1).hash.should == @u.hash
138
+ end
139
+ end
140
+
141
+ describe "undirected_edge_sort" do
142
+ it do
143
+ x = [Edge.new(12, 1), Edge.new(2,11)].sort
144
+ x.should == [Edge.new(2,11), Edge.new(1,12)]
145
+ end
146
+ end
147
+
148
+ describe "hash" do
149
+ it do
150
+ Arc[1,2,:c].should == Arc[1,2,:b]
151
+ Arc[1,2,:c].hash.should == Arc[1,2,:b].hash
152
+ Arc[1,2].should_not == Arc[2,1]
153
+ Arc[1,2].should_not == Edge[1,2]
154
+ Edge[1,2].should == Edge[2,1]
155
+ Edge[1,2,:a].should == Edge[2,1,:b]
156
+ end
157
+ end
158
+
159
+ end