jumoku 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/Gemfile +0 -1
  2. data/lib/jumoku.rb +2 -3
  3. data/lib/jumoku/builders/extended.rb +15 -23
  4. data/lib/jumoku/builders/raw_directed_tree.rb +15 -0
  5. data/lib/jumoku/builders/raw_undirected_tree.rb +15 -0
  6. data/lib/jumoku/builders/shared.rb +2 -5
  7. data/lib/jumoku/support/ruby_compatibility.rb +19 -0
  8. data/lib/jumoku/version.rb +1 -1
  9. data/spec/arborescence_spec.rb +14 -0
  10. data/spec/behaviors/core_tree.rb +281 -0
  11. data/spec/behaviors/extended.rb +530 -0
  12. data/spec/raw_directed_tree_spec.rb +14 -0
  13. data/spec/raw_undirected_tree_spec.rb +9 -310
  14. data/spec/spec_helper.rb +2 -0
  15. data/spec/tree_spec.rb +8 -535
  16. metadata +21 -86
  17. data/lib/jumoku/tree_api.rb +0 -27
  18. data/vendor/git/plexus/CREDITS.md +0 -31
  19. data/vendor/git/plexus/Gemfile +0 -3
  20. data/vendor/git/plexus/Gemfile.lock +0 -28
  21. data/vendor/git/plexus/LICENSE +0 -37
  22. data/vendor/git/plexus/README.md +0 -208
  23. data/vendor/git/plexus/Rakefile +0 -25
  24. data/vendor/git/plexus/TODO.md +0 -20
  25. data/vendor/git/plexus/VERSION +0 -1
  26. data/vendor/git/plexus/examples/graph_self.rb +0 -56
  27. data/vendor/git/plexus/examples/module_graph.jpg +0 -0
  28. data/vendor/git/plexus/examples/module_graph.rb +0 -14
  29. data/vendor/git/plexus/examples/self_graph.jpg +0 -0
  30. data/vendor/git/plexus/examples/visualize.jpg +0 -0
  31. data/vendor/git/plexus/examples/visualize.rb +0 -10
  32. data/vendor/git/plexus/lib/plexus.rb +0 -90
  33. data/vendor/git/plexus/lib/plexus/adjacency_graph.rb +0 -224
  34. data/vendor/git/plexus/lib/plexus/arc.rb +0 -59
  35. data/vendor/git/plexus/lib/plexus/arc_number.rb +0 -52
  36. data/vendor/git/plexus/lib/plexus/biconnected.rb +0 -84
  37. data/vendor/git/plexus/lib/plexus/chinese_postman.rb +0 -91
  38. data/vendor/git/plexus/lib/plexus/classes/graph_classes.rb +0 -28
  39. data/vendor/git/plexus/lib/plexus/common.rb +0 -63
  40. data/vendor/git/plexus/lib/plexus/comparability.rb +0 -63
  41. data/vendor/git/plexus/lib/plexus/directed_graph.rb +0 -78
  42. data/vendor/git/plexus/lib/plexus/directed_graph/algorithms.rb +0 -95
  43. data/vendor/git/plexus/lib/plexus/directed_graph/distance.rb +0 -167
  44. data/vendor/git/plexus/lib/plexus/dot.rb +0 -94
  45. data/vendor/git/plexus/lib/plexus/edge.rb +0 -36
  46. data/vendor/git/plexus/lib/plexus/ext.rb +0 -79
  47. data/vendor/git/plexus/lib/plexus/graph.rb +0 -626
  48. data/vendor/git/plexus/lib/plexus/graph_api.rb +0 -35
  49. data/vendor/git/plexus/lib/plexus/labels.rb +0 -113
  50. data/vendor/git/plexus/lib/plexus/maximum_flow.rb +0 -77
  51. data/vendor/git/plexus/lib/plexus/ruby_compatibility.rb +0 -17
  52. data/vendor/git/plexus/lib/plexus/search.rb +0 -510
  53. data/vendor/git/plexus/lib/plexus/strong_components.rb +0 -93
  54. data/vendor/git/plexus/lib/plexus/support/support.rb +0 -9
  55. data/vendor/git/plexus/lib/plexus/undirected_graph.rb +0 -56
  56. data/vendor/git/plexus/lib/plexus/undirected_graph/algorithms.rb +0 -90
  57. data/vendor/git/plexus/lib/plexus/version.rb +0 -6
  58. data/vendor/git/plexus/plexus.gemspec +0 -24
  59. data/vendor/git/plexus/spec/biconnected_spec.rb +0 -27
  60. data/vendor/git/plexus/spec/chinese_postman_spec.rb +0 -27
  61. data/vendor/git/plexus/spec/community_spec.rb +0 -44
  62. data/vendor/git/plexus/spec/complement_spec.rb +0 -27
  63. data/vendor/git/plexus/spec/digraph_distance_spec.rb +0 -121
  64. data/vendor/git/plexus/spec/digraph_spec.rb +0 -339
  65. data/vendor/git/plexus/spec/dot_spec.rb +0 -48
  66. data/vendor/git/plexus/spec/edge_spec.rb +0 -158
  67. data/vendor/git/plexus/spec/inspection_spec.rb +0 -38
  68. data/vendor/git/plexus/spec/multi_edge_spec.rb +0 -32
  69. data/vendor/git/plexus/spec/neighborhood_spec.rb +0 -36
  70. data/vendor/git/plexus/spec/properties_spec.rb +0 -146
  71. data/vendor/git/plexus/spec/search_spec.rb +0 -227
  72. data/vendor/git/plexus/spec/spec.opts +0 -4
  73. data/vendor/git/plexus/spec/spec_helper.rb +0 -59
  74. data/vendor/git/plexus/spec/strong_components_spec.rb +0 -61
  75. data/vendor/git/plexus/spec/triangulated_spec.rb +0 -125
  76. data/vendor/git/plexus/spec/undirected_graph_spec.rb +0 -220
  77. data/vendor/git/plexus/vendor/priority-queue/CHANGELOG +0 -33
  78. data/vendor/git/plexus/vendor/priority-queue/Makefile +0 -140
  79. data/vendor/git/plexus/vendor/priority-queue/README +0 -133
  80. data/vendor/git/plexus/vendor/priority-queue/benchmark/dijkstra.rb +0 -171
  81. data/vendor/git/plexus/vendor/priority-queue/compare_comments.rb +0 -49
  82. data/vendor/git/plexus/vendor/priority-queue/doc/c-vs-rb.png +0 -0
  83. data/vendor/git/plexus/vendor/priority-queue/doc/compare_big.gp +0 -14
  84. data/vendor/git/plexus/vendor/priority-queue/doc/compare_big.png +0 -0
  85. data/vendor/git/plexus/vendor/priority-queue/doc/compare_small.gp +0 -15
  86. data/vendor/git/plexus/vendor/priority-queue/doc/compare_small.png +0 -0
  87. data/vendor/git/plexus/vendor/priority-queue/doc/results.csv +0 -37
  88. data/vendor/git/plexus/vendor/priority-queue/ext/priority_queue/CPriorityQueue/extconf.rb +0 -2
  89. data/vendor/git/plexus/vendor/priority-queue/ext/priority_queue/CPriorityQueue/priority_queue.c +0 -947
  90. data/vendor/git/plexus/vendor/priority-queue/lib/priority_queue.rb +0 -14
  91. data/vendor/git/plexus/vendor/priority-queue/lib/priority_queue/c_priority_queue.rb +0 -1
  92. data/vendor/git/plexus/vendor/priority-queue/lib/priority_queue/poor_priority_queue.rb +0 -46
  93. data/vendor/git/plexus/vendor/priority-queue/lib/priority_queue/ruby_priority_queue.rb +0 -526
  94. data/vendor/git/plexus/vendor/priority-queue/priority_queue.so +0 -0
  95. data/vendor/git/plexus/vendor/priority-queue/setup.rb +0 -1551
  96. data/vendor/git/plexus/vendor/priority-queue/test/priority_queue_test.rb +0 -371
  97. data/vendor/git/plexus/vendor/rdot.rb +0 -360
@@ -0,0 +1,530 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for "a tree with extended features" do
4
+ describe "#new" do
5
+ it "should create a valid tree graph" do
6
+ tree.should be_valid
7
+ tree.nodes.should be_empty
8
+ end
9
+ end
10
+
11
+ describe "#add_node" do
12
+ describe "an empty tree" do
13
+ it "should create a new, valid tree with a single node when its first node is added" do
14
+ tree.add_node 1
15
+ tree.should be_empty # the original tree is not modified
16
+ # a brand new tree is created instead, extending the original one
17
+ new_tree = tree.add_node 1
18
+ new_tree.nodes.should == [1]
19
+ new_tree.should be_valid
20
+ end
21
+ end
22
+
23
+ describe "a populated tree" do
24
+ before :each do
25
+ tree.add_branch! 1, 2
26
+ tree.add_branch! 2, 3
27
+ tree.add_branch! 3, 4
28
+ end
29
+
30
+ it "should create a new, extended, valid tree when an additionnal node is added" do
31
+ tree.add_node 5, 4
32
+ tree.add_node 3, 6
33
+ tree.nodes.size.should == 4
34
+
35
+ new_tree = tree.add_node 5, 4
36
+ new_tree.nodes.size.should == tree.nodes.size + 1
37
+ new_tree.nodes.sort.should == [1, 2, 3, 4, 5]
38
+ new_tree.should be_valid
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "#add_branch" do
44
+ describe "an empty tree" do
45
+ it "should create a new, valid tree with only two nodes when a branch is added" do
46
+ new_tree = tree.add_branch 1, 2
47
+ tree.should be_empty
48
+ tree.should be_valid
49
+ new_tree.nodes.sort.should == [1,2]
50
+ new_tree.should be_valid
51
+ end
52
+ end
53
+
54
+ describe "a populated tree" do
55
+ before :each do
56
+ tree.add_branch! 1, 2
57
+ tree.add_branch! 2, 3
58
+ tree.add_branch! 3, 4
59
+ end
60
+
61
+ it "should create a new, extended, valid tree when a branch is added" do
62
+ tree.add_branch 5, 4
63
+ tree.add_branch 3, 6
64
+
65
+ tree.nodes.size.should == 4
66
+
67
+ new_tree = tree.add_branch 5, 4
68
+
69
+ new_tree.nodes.size.should == tree.nodes.size + 1
70
+ new_tree.nodes.sort.should == [1, 2, 3, 4, 5]
71
+ new_tree.should be_valid
72
+ end
73
+ end
74
+ end
75
+
76
+ describe "#remove_node" do
77
+ describe "an empty tree" do
78
+ it "should raise an error when trying to remove a node" do
79
+ lambda { tree.remove_node :null }.should raise_error, RawTreeError
80
+ end
81
+ end
82
+
83
+ describe "a tree containing one node" do
84
+ before :each do
85
+ tree.add_node! 1
86
+ end
87
+
88
+ it "should create a new, empty, valid tree" do
89
+ new_tree = tree.remove_node 1
90
+ tree.nodes.should == [1]
91
+ tree.should be_valid
92
+ new_tree.should be_empty
93
+ new_tree.should be_valid
94
+ end
95
+ end
96
+ end
97
+
98
+ # FIXME: what's this force option?
99
+ describe "#remove_branch" do
100
+ describe "an empty tree" do
101
+ it "should not allow for removing a branch (even if forced to)" do
102
+ lambda { tree.remove_branch 1, 2 }.should raise_error, RawTreeError
103
+ lambda { tree.remove_branch 1, 2, :force => true }.should raise_error, RawTreeError
104
+ end
105
+ end
106
+
107
+ describe "a tree that's one node" do
108
+ before :each do
109
+ tree.add_node! 1
110
+ end
111
+
112
+ it "should not allow for removing a branch (even if forced to)" do
113
+ lambda { tree.remove_branch 1, 2 }.should raise_error, RawTreeError
114
+ lambda { tree.remove_branch 1, 2, :force => true }.should raise_error, RawTreeError
115
+ end
116
+ end
117
+
118
+ describe "a tree with at least two nodes" do
119
+ before :each do
120
+ tree.add_branch! 1, 2
121
+ tree.add_branch! 2, 3
122
+ end
123
+
124
+ it "should allow for removing a branch, creating a new, valid tree" do
125
+ lambda { tree.remove_branch 1, 2, :force => true }.should_not raise_error
126
+ new_tree = tree.remove_branch 1, 2, :force => true
127
+ tree.nodes.should == [1, 2, 3]
128
+ new_tree.nodes.sort.should == [2, 3]
129
+ new_tree.should be_valid
130
+ end
131
+ end
132
+ end
133
+
134
+ # TODO: test more edge-cases
135
+ describe "#add_nodes!" do
136
+ describe "an empty tree" do
137
+ it "should allow for adding its first nodes, by pairs and branches" do
138
+ tree.add_nodes! 1,2, 2,3, 3,4
139
+ tree.nodes.sort.should == [1, 2, 3, 4]
140
+ tree.should be_valid
141
+
142
+ tree.add_nodes! branch_type.new(5, 2)
143
+ tree.nodes.sort.should == [1, 2, 3, 4, 5]
144
+ tree.should be_valid
145
+
146
+ tree.add_nodes! 3,4, 1,10, branch_type.new(10, 11), -1,1
147
+ tree.nodes.size.should == 8
148
+ tree.should be_valid
149
+
150
+ lambda { tree.add_nodes! 10, 11 }.should_not raise_error
151
+ lambda { tree.add_nodes! 1, 11 }.should raise_error, RawTreeError # cycle
152
+ end
153
+ end
154
+ end
155
+
156
+ describe "#add_nodes" do
157
+ describe "an empty tree" do
158
+ it "should allow for adding its first nodes, by pairs and branches, creating a new, valid tree" do
159
+ new_tree = tree.add_nodes 1,2, 2,3, 3,4
160
+ tree.should be_empty
161
+ new_tree.nodes.sort.should == [1, 2, 3, 4]
162
+ new_tree.should be_valid
163
+
164
+ new_tree = tree.add_nodes branch_type.new(4, 5)
165
+ tree.should be_empty
166
+ new_tree.nodes.sort.should == [4, 5]
167
+ new_tree.should be_valid
168
+
169
+ new_tree = tree.add_nodes 3,4, 4,10, branch_type.new(10, 11), -1,3
170
+ tree.should be_empty
171
+ new_tree.nodes.size.should == 5
172
+ new_tree.should be_valid
173
+
174
+ lambda { tree.add_nodes 10, 11 }.should_not raise_error
175
+ end
176
+ end
177
+ end
178
+
179
+ describe "#add_branches!" do
180
+ describe "an empty tree" do
181
+ it "should allow for adding its first branches" do
182
+ tree.add_branches! branch_type.new(1, 2), 1,3, 3,4
183
+ tree.nodes.sort.should == [1, 2, 3, 4]
184
+ tree.should be_valid
185
+
186
+ branch = branch_type.new(1, 4)
187
+ lambda { tree.add_branches! branch }.should raise_error, RawTreeError
188
+ end
189
+ end
190
+
191
+ describe "a populated tree" do
192
+ before :each do
193
+ tree.add_nodes! 1, 2
194
+ end
195
+
196
+ it "should allow for adding new branches" do
197
+ tree.add_branches! 2, 3
198
+ tree.nodes.sort.should == [1, 2, 3]
199
+ tree.should be_valid
200
+
201
+ tree.add_branches! branch_type.new(0,1), 3,4, branch_type.new(4,5)
202
+ [0..5].all? { |n| tree.nodes.include? n } and tree.nodes.size.should == 5
203
+ tree.should be_valid
204
+
205
+ lambda { tree.add_branches! branch_type.new(2, 5) }.should raise_error, RawTreeError
206
+ end
207
+ end
208
+ end
209
+
210
+ describe "add_branches" do
211
+ describe "an empty tree" do
212
+ it "should create a new, valid tree populated with its first branches" do
213
+ b1, b2, b3 = branch_type.new(1, 2), branch_type.new(2, 3), branch_type.new(3, 4)
214
+ new_tree = tree.add_branches b1, b2, b3
215
+ tree.should be_empty
216
+ new_tree.nodes.sort.should == [1, 2, 3, 4]
217
+ new_tree.should be_valid
218
+
219
+ lambda { tree.add_branches 1,2, 2,3, 3,1 }.should raise_error, RawTreeError
220
+ end
221
+ end
222
+
223
+ describe "a populated tree" do
224
+ before :each do
225
+ tree.add_nodes! 1,2, 2,3, 3,4
226
+ end
227
+
228
+ it "should create a new, valid tree extended with its new branches" do
229
+ new_tree = tree.add_branches 4, 5, branch_type.new(5, 6)
230
+ tree.nodes.sort.should == (1..4).to_a
231
+ new_tree.nodes.sort.should == [1, 2, 3, 4, 5, 6]
232
+ new_tree.should be_valid
233
+
234
+ lambda { tree.add_branches 10, 11 }.should raise_error, RawTreeError
235
+ lambda { tree.add_branches branch_type.new 1,4 }.should raise_error, RawTreeError
236
+ end
237
+ end
238
+ end
239
+
240
+ describe "#remove_nodes!" do
241
+ describe "an empty tree" do
242
+ it "should not allow for removing nodes" do
243
+ lambda { tree.remove_nodes! :foo, :bar }.should raise_error, RawTreeError
244
+ end
245
+ end
246
+
247
+ describe "a tree that's one node" do
248
+ before :each do
249
+ tree.add_node! :one
250
+ end
251
+
252
+ it "should allow for removing its sole node only (bad semantic)" do
253
+ tree.remove_nodes! :one
254
+ tree.nodes.should be_empty
255
+ tree.should be_valid
256
+
257
+ lambda { tree.remove_nodes! :foo, :bar }.should raise_error, RawTreeError
258
+ end
259
+ end
260
+
261
+ describe "a populated tree" do
262
+ before :each do
263
+ tree.add_nodes! 1,2, 2,3, 3,4
264
+ end
265
+
266
+ it "should allow for removing its nodes until it's empty" do
267
+ tree.remove_nodes! 1, 2..4
268
+ tree.should be_empty
269
+ tree.should be_valid
270
+
271
+ lambda { tree.remove_nodes! :undefinedNode }.should raise_error, RawTreeError
272
+ end
273
+ end
274
+ end
275
+
276
+ describe "#remove_nodes" do
277
+ describe "an empty tree" do
278
+ it "should not allow for removing nodes" do
279
+ lambda { tree.remove_nodes :foo, :bar }.should raise_error, RawTreeError
280
+ end
281
+ end
282
+
283
+ describe "a populated tree" do
284
+ before :each do
285
+ tree.add_nodes! 1,2, 2,3, 3,4
286
+ end
287
+
288
+ it "should allow for removing nodes, creating a new, valid tree" do
289
+ new_tree = tree.remove_nodes 1, 2, 3, 4
290
+ tree.nodes.sort.should == [1, 2, 3, 4]
291
+ new_tree.should be_empty
292
+ new_tree.should be_valid
293
+
294
+ lambda { tree.remove_nodes! :null }.should raise_error, RawTreeError
295
+ end
296
+ end
297
+ end
298
+
299
+ describe "#remove_branches!" do
300
+ describe "an empty tree" do
301
+ it "should not allow for removing branches" do
302
+ lambda { tree.remove_branches branch_type.new(:foo, :bar), 1,2 }.should raise_error, RawTreeError
303
+ end
304
+ end
305
+
306
+ describe "a tree that's only one node" do
307
+ before :each do
308
+ tree.add_node! :solo
309
+ end
310
+
311
+ it "should not allow for removing branches" do
312
+ lambda { tree.remove_branches! :solo, :null }.should raise_error, RawTreeError
313
+ end
314
+ end
315
+
316
+ describe "a populated tree" do
317
+ before :each do
318
+ tree.add_nodes! 1,2, 2,3, 3,4
319
+ end
320
+
321
+ it "should allow for removing branches until it has no more branches or a sole node" do
322
+ tree.remove_branches! 1,2, branch_type.new(2,3), 3,4
323
+ tree.should be_empty
324
+ tree.should be_valid
325
+
326
+ lambda { tree.remove_branches! branch_type.new(:foo, :bar), branch_type.new(1, 2) }.should raise_error, RawTreeError
327
+ end
328
+ end
329
+ end
330
+
331
+ describe "#remove_branches" do
332
+ describe "an empty tree" do
333
+ it "should not allow for removing branches" do
334
+ lambda { tree.remove_branches :foo, :bar, branch_type.new(1, 2) }.should raise_error, RawTreeError
335
+ end
336
+ end
337
+
338
+ describe "a tree that's one node" do
339
+ before :each do
340
+ tree.add_node! :solo
341
+ end
342
+
343
+ it "should not allow for removing branches" do
344
+ lambda { tree.remove_branches :solo, :null }.should raise_error, RawTreeError
345
+ end
346
+ end
347
+
348
+ describe "a populated tree" do
349
+ before :each do
350
+ tree.add_nodes! 1,2, 2,3, 3,4
351
+ end
352
+
353
+ it "should allow for removing branches until it has no more branches or a sole node, creating a new, valid tree" do
354
+ new_tree = tree.remove_branches 1,2, branch_type.new(2,3), 3,4
355
+ tree.nodes.sort.should == [1, 2, 3, 4]
356
+ new_tree.should be_empty
357
+ new_tree.should be_valid
358
+
359
+ lambda { tree.remove_branches branch_type.new(:foo, :bar), branch_type.new(1, 2) }.should raise_error, RawTreeError
360
+ end
361
+ end
362
+ end
363
+
364
+ describe "#node?" do
365
+ describe "an empty tree" do
366
+ it "should not report having any node" do
367
+ tree.node?(:null).should be_false
368
+ end
369
+ end
370
+
371
+ describe "a populated tree" do
372
+ before :each do
373
+ tree.add_nodes! 1,2, 2,3, 3,4
374
+ end
375
+
376
+ it "should be aware of which nodes belong to itself" do
377
+ tree.node?(1).should be_true
378
+ tree.has_node?(:null).should be_false
379
+ end
380
+ end
381
+ end
382
+
383
+ describe "#nodes?" do
384
+ describe "an empty tree" do
385
+ it "should not report having any node" do
386
+ tree.nodes?(:null, :foo, 0).should be_false
387
+ end
388
+ end
389
+
390
+ describe "a populated tree" do
391
+ before :each do
392
+ tree.add_nodes! 1,2, 2,3, 3,4
393
+ end
394
+
395
+ it "should be aware of which nodes belong to itself" do
396
+ tree.nodes?(1, 4).should be_true
397
+ tree.has_nodes?(:null, 1, 2).should be_false
398
+ end
399
+ end
400
+ end
401
+
402
+ describe "#nodes_among?" do
403
+ describe "an empty tree" do
404
+ it "should not report having any node" do
405
+ tree.nodes_among?(:null, :foo, 0).should be_false
406
+ end
407
+ end
408
+
409
+ describe "a populated tree" do
410
+ before :each do
411
+ tree.add_nodes! 1,2, 2,3, 3,4
412
+ end
413
+
414
+ it "should be aware of which nodes belong to itself" do
415
+ tree.nodes_among?(1, 4).should be_true
416
+ tree.has_node_among?(:foo, 2, :bar).should be_true
417
+ tree.has_nodes_among?(:foo, 2, :bar, 3, 4, Array.new).should be_true
418
+ tree.has_nodes_among?(:null, :foo, :bar).should be_false
419
+ end
420
+ end
421
+ end
422
+
423
+ describe "#branch?" do
424
+ describe "an empty tree" do
425
+ it "should not have any branch" do
426
+ tree.has_branch?(1,2).should be_false
427
+ end
428
+ end
429
+
430
+ describe "a tree that's one node" do
431
+ before :each do
432
+ tree.add_node! :solo
433
+ end
434
+
435
+ it "should not have any branch" do
436
+ tree.has_branch?(1,2).should be_false
437
+ end
438
+ end
439
+
440
+ describe "a populated tree" do
441
+ before :each do
442
+ tree.add_nodes! 1,2, 2,3, 3,4
443
+ end
444
+
445
+ it "should be aware of which branches belong to itself" do
446
+ tree.has_branch?(2,3).should be_true
447
+ tree.has_branch?(1,3).should be_false
448
+ tree.has_branch?(1,:null).should be_false
449
+ end
450
+ end
451
+ end
452
+
453
+ # TODO: tests for #branches? and #branches_among?
454
+ # (actually, done within the tests for #add_consecutive_nodes!)
455
+
456
+ describe "#num_nodes" do
457
+ describe "an empty tree" do
458
+ it "should report having no node" do
459
+ tree.number_of_nodes.should == 0
460
+ end
461
+ end
462
+
463
+ describe "a populated tree" do
464
+ before :each do
465
+ tree.add_nodes! 1,2, 2,3, 3,4
466
+ end
467
+
468
+ it "should report how many nodes belong to it" do
469
+ tree.number_of_nodes.should == 4
470
+ end
471
+ end
472
+ end
473
+
474
+ describe "#num_branches" do
475
+ describe "an empty tree" do
476
+ it "should report having no branch" do
477
+ tree.number_of_nodes.should == 0
478
+ end
479
+ end
480
+
481
+ describe "a tree that's one node" do
482
+ before :each do
483
+ tree.add_node! :solo
484
+ end
485
+
486
+ it "should report having no branch" do
487
+ tree.number_of_branches.should == 0
488
+ end
489
+ end
490
+
491
+ describe "a populated tree" do
492
+ before :each do
493
+ tree.add_nodes! 1,2, 2,3, 3,4
494
+ end
495
+
496
+ it "should report how many branches belong to it" do
497
+ tree.number_of_branches.should == tree.number_of_nodes - 1
498
+ end
499
+ end
500
+ end
501
+
502
+ describe "#add_consecutive_nodes!" do
503
+ describe "a tree" do
504
+ it "should grow as a valid, populated tree if all specified nodes define a valid tree structure" do
505
+ tree.add_consecutive_nodes!(1, 2, 3, :four, branch_type.new(:foo, "bar"))
506
+
507
+ tree.has_branches?(1,2, 2,3, branch_type.new(3, :four), :four,:foo, :foo,"bar").should be_true # each specified branch exist
508
+ tree.has_branches?(1,2, 2,3, branch_type.new(3, :four), :four,:foo).should be_true # each specified branch exist
509
+ tree.has_branches_among?(1,2, 2,3, branch_type.new(3, :four), :four,:foo).should be_false # do not list every existing branch
510
+ tree.has_branches_among?(1,2, 2,3, branch_type.new(3, :four), :four,:foo, :foo,"bar").should be_true # list all existing branches
511
+ tree.has_branches_among?(1,2, 2,3, branch_type.new(3, :four), :four,:foo, :foo,"bar", Array.new, "NIL").should be_true # list all existing branches
512
+ tree.should be_valid
513
+ end
514
+ end
515
+ end
516
+
517
+ describe "#add_consecutive_nodes" do
518
+ describe "a tree" do
519
+ it "should create a new, valid, populated tree if all specified nodes define a valid tree structure" do
520
+ new_tree = tree.add_consecutive_nodes(1, 2, 3, :four, branch_type.new(:foo, "bar"))
521
+
522
+ tree.should be_empty
523
+ new_tree.has_branches?(1,2, 2,3, branch_type.new(3, :four), :four,:foo, :foo,"bar").should be_true
524
+ new_tree.has_branches?(1,2, 2,3, branch_type.new(3, :four), :four,:foo).should be_true
525
+ new_tree.should be_valid
526
+ end
527
+ end
528
+ end
529
+ end
530
+