rubytree 0.9.2 → 0.9.3pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04cb1c44d2c9f5c11c5f9202b0e24202e287579a
4
- data.tar.gz: a6b6581c4b1bcc106896889a092ece86a93e3bb5
3
+ metadata.gz: 3dd9b9757055ea2f6896146448b13996c7e099cf
4
+ data.tar.gz: 96f4a3cce558178889c67e64984778ad2192f42f
5
5
  SHA512:
6
- metadata.gz: 9dcc9b36d0ca03c71c11658e637086ee9f2decbbe1429f296ea38afbc73c2902b5375387429c882329a64d2740ad43eb3abb0de34be03a4b58413c0098e36722
7
- data.tar.gz: 33dc63cd509b22d768c29cca9dd7c75744add483b6003577df13ce3990541d38113420a17ad5b74c72993796b80e692164c1d7e580b91ccdf301505b4a1fb36a
6
+ metadata.gz: 32066b906cf88e1cba0ebc79c3b824e2f074ca884d90ddbbff76ee128ecc9f13c584fa362231f58c81ffc733574a4a780700e3d7b458b95476fe81920f17a71f
7
+ data.tar.gz: 7d1eef090b839f6c8a3335d0fc5b8820aea6a614d2c7e2f6de3b784dd318f39fe99ef6bdec5d7105cb4c17c1c403bf69524b1f7411ee7f8d07aba843dc211a34
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubytree (0.9.2)
4
+ rubytree (0.9.3pre)
5
5
  json (~> 1.8)
6
6
  structured_warnings (~> 0.1)
7
7
 
@@ -14,12 +14,13 @@ GEM
14
14
  simplecov (>= 0.7)
15
15
  term-ansicolor
16
16
  thor
17
- docile (1.1.1)
17
+ docile (1.1.2)
18
18
  json (1.8.1)
19
19
  mime-types (2.0)
20
- multi_json (1.8.2)
20
+ multi_json (1.8.4)
21
21
  rake (10.1.1)
22
- rdoc (4.1.0)
22
+ rdoc (4.1.1)
23
+ json (~> 1.4)
23
24
  rest-client (1.6.7)
24
25
  mime-types (>= 1.16)
25
26
  rtags (0.98)
data/TAGS ADDED
@@ -0,0 +1,222 @@
1
+
2
+ lib/rubytree.rb,0
3
+
4
+ lib/tree/binarytree.rb,727
5
+ module Tree::Tree43,1900
6
+ class BinaryTreeNode::Tree::BinaryTreeNode52,2209
7
+ def left_child::Tree::BinaryTreeNode#left_child62,2492
8
+ def right_child::Tree::BinaryTreeNode#right_child74,2883
9
+ def is_left_child?::Tree::BinaryTreeNode#is_left_child?83,3159
10
+ def is_right_child?::Tree::BinaryTreeNode#is_right_child?93,3490
11
+ def add::Tree::BinaryTreeNode#add110,4147
12
+ def inordered_each::Tree::BinaryTreeNode#inordered_each128,4666
13
+ def set_child_at::Tree::BinaryTreeNode#set_child_at159,5602
14
+ def left_child=::Tree::BinaryTreeNode#left_child=178,6270
15
+ def right_child=::Tree::BinaryTreeNode#right_child=190,6639
16
+ def swap_children::Tree::BinaryTreeNode#swap_children195,6785
17
+
18
+ lib/tree/tree_deps.rb,0
19
+
20
+ lib/tree/utils/camel_case_method_handler.rb,324
21
+ module Tree::Tree41,1848
22
+ module CamelCaseMethodHandler::Tree::CamelCaseMethodHandler44,2004
23
+ def self.included::Tree::CamelCaseMethodHandler.included45,2038
24
+ def method_missing::Tree::CamelCaseMethodHandler#method_missing49,2186
25
+ def to_snake_case::Tree::CamelCaseMethodHandler#to_snake_case66,2798
26
+
27
+ lib/tree/utils/json_converter.rb,258
28
+ module Tree::Tree42,1899
29
+ def self.included::Tree.included44,1936
30
+ def as_json::Tree#as_json61,2387
31
+ def to_json::Tree#to_json89,3095
32
+ module ClassMethods::Tree::ClassMethods94,3245
33
+ def json_create::Tree::ClassMethods#json_create113,3960
34
+
35
+ lib/tree/utils/metrics_methods.rb,718
36
+ module Tree::Tree41,1833
37
+ module TreeMetricsHandler::Tree::TreeMetricsHandler43,1918
38
+ def self.included::Tree::TreeMetricsHandler.included44,1948
39
+ def size::Tree::TreeMetricsHandler#size56,2317
40
+ def length::Tree::TreeMetricsHandler#length67,2661
41
+ def node_height::Tree::TreeMetricsHandler#node_height80,3078
42
+ def node_depth::Tree::TreeMetricsHandler#node_depth96,3689
43
+ def level::Tree::TreeMetricsHandler#level105,3875
44
+ def depth::Tree::TreeMetricsHandler#depth124,4560
45
+ def breadth::Tree::TreeMetricsHandler#breadth140,5197
46
+ def in_degree::Tree::TreeMetricsHandler#in_degree154,5660
47
+ def out_degree::Tree::TreeMetricsHandler#out_degree165,5973
48
+
49
+ lib/tree/utils/tree_merge_handler.rb,214
50
+ module Tree::Tree40,1769
51
+ def merge::Tree#merge57,2500
52
+ def merge!::Tree#merge!72,3134
53
+ def check_merge_prerequisites::Tree#check_merge_prerequisites85,3441
54
+ def merge_trees::Tree#merge_trees102,4086
55
+
56
+ lib/tree/utils/utils.rb,27
57
+ module Tree::Tree39,1838
58
+
59
+ lib/tree/version.rb,27
60
+ module Tree::Tree38,1723
61
+
62
+ lib/tree.rb,2676
63
+ module Tree::Tree48,2158
64
+ class TreeNode::Tree::TreeNode85,3731
65
+ attr_reader :name::Tree::TreeNode#name108,4483
66
+ attr_accessor :content::Tree::TreeNode#content115,4682
67
+ attr_reader :parent::Tree::TreeNode#parent119,4798
68
+ def root::Tree::TreeNode#root126,5010
69
+ def is_root?::Tree::TreeNode#is_root?137,5316
70
+ def has_content?::Tree::TreeNode#has_content?145,5499
71
+ def is_leaf?::Tree::TreeNode#is_leaf?156,5753
72
+ def parentage::Tree::TreeNode#parentage168,6128
73
+ def has_children?::Tree::TreeNode#has_children?186,6554
74
+ def initialize::Tree::TreeNode#Tree::TreeNode.new209,7380
75
+ def detached_copy::Tree::TreeNode#detached_copy227,7997
76
+ def detached_subtree_copy::Tree::TreeNode#detached_subtree_copy237,8283
77
+ alias :dup::Tree::TreeNode#dup246,8544
78
+ def marshal_dump::Tree::TreeNode#marshal_dump251,8722
79
+ def create_dump_rep::Tree::TreeNode#create_dump_rep257,8890
80
+ def marshal_load::Tree::TreeNode#marshal_load272,9428
81
+ def to_s::Tree::TreeNode#to_s297,10212
82
+ def <<::Tree::TreeNode#<<320,10983
83
+ def add::Tree::TreeNode#add355,12489
84
+ def insertion_range::Tree::TreeNode#insertion_range375,13549
85
+ def remove!::Tree::TreeNode#remove!397,14336
86
+ def parent=::Tree::TreeNode#parent=412,14739
87
+ def remove_from_parent!::Tree::TreeNode#remove_from_parent!425,15124
88
+ def remove_all!::Tree::TreeNode#remove_all!436,15496
89
+ def set_as_root!::Tree::TreeNode#set_as_root!447,15725
90
+ def freeze_tree!::Tree::TreeNode#freeze_tree!457,16051
91
+ def []::Tree::TreeNode#[]497,17569
92
+ def each::Tree::TreeNode#each522,18536
93
+ def preordered_each::Tree::TreeNode#preordered_each550,19496
94
+ def postordered_each::Tree::TreeNode#postordered_each562,19908
95
+ def breadth_each::Tree::TreeNode#breadth_each598,21334
96
+ def children::Tree::TreeNode#children624,22272
97
+ def each_leaf::Tree::TreeNode#each_leaf645,22893
98
+ def first_child::Tree::TreeNode#first_child662,23315
99
+ def last_child::Tree::TreeNode#last_child670,23526
100
+ def first_sibling::Tree::TreeNode#first_sibling686,23973
101
+ def is_first_sibling?::Tree::TreeNode#is_first_sibling?696,24247
102
+ def last_sibling::Tree::TreeNode#last_sibling710,24663
103
+ def is_last_sibling?::Tree::TreeNode#is_last_sibling?720,24933
104
+ def siblings::Tree::TreeNode#siblings736,25486
105
+ def is_only_child?::Tree::TreeNode#is_only_child?755,26038
106
+ def next_sibling::Tree::TreeNode#next_sibling768,26441
107
+ def previous_sibling::Tree::TreeNode#previous_sibling784,26915
108
+ def <=>::Tree::TreeNode#<=>800,27426
109
+ def print_tree::Tree::TreeNode#print_tree808,27655
110
+
111
+ test/run_test.rb,0
112
+
113
+ test/test_binarytree.rb,1192
114
+ module TestTree::TestTree39,1717
115
+ class TestBinaryTreeNode::TestTree::TestBinaryTreeNode41,1776
116
+ def setup::TestTree::TestBinaryTreeNode#setup44,1868
117
+ def teardown::TestTree::TestBinaryTreeNode#teardown52,2171
118
+ def test_initialize::TestTree::TestBinaryTreeNode#test_initialize59,2330
119
+ def test_add::TestTree::TestBinaryTreeNode#test_add67,2719
120
+ def test_inordered_each::TestTree::TestBinaryTreeNode#test_inordered_each90,3633
121
+ def test_left_child::TestTree::TestBinaryTreeNode#test_left_child134,5101
122
+ def test_right_child::TestTree::TestBinaryTreeNode#test_right_child142,5414
123
+ def test_left_child_equals::TestTree::TestBinaryTreeNode#test_left_child_equals150,5727
124
+ def test_right_child_equals::TestTree::TestBinaryTreeNode#test_right_child_equals169,6717
125
+ def test_is_left_child_eh::TestTree::TestBinaryTreeNode#test_is_left_child_eh189,7834
126
+ def test_is_right_child_eh::TestTree::TestBinaryTreeNode#test_is_right_child_eh204,8373
127
+ def test_swap_children::TestTree::TestBinaryTreeNode#test_swap_children218,8919
128
+ def test_old_camelCase_method_names::TestTree::TestBinaryTreeNode#test_old_camelCase_method_names236,9802
129
+
130
+ test/test_rubytree_require.rb,203
131
+ module TestTree::TestTree38,1678
132
+ class TestRequireRubytree::TestTree::TestRequireRubytree41,1759
133
+ def test_create_a_simple_node::TestTree::TestRequireRubytree#test_create_a_simple_node44,1884
134
+
135
+ test/test_subclassed_node.rb,389
136
+ module TestTree::TestTree39,1688
137
+ class TestSubclassedTreeNode::TestTree::TestSubclassedTreeNode42,1741
138
+ class MyNode::TestTree::TestSubclassedTreeNode::MyNode45,1868
139
+ def my_dummy_method::TestTree::TestSubclassedTreeNode::MyNode#my_dummy_method47,1967
140
+ def test_subclassed_camelcase_methods::TestTree::TestSubclassedTreeNode#test_subclassed_camelcase_methods52,2026
141
+
142
+ test/test_thread_and_fiber.rb,422
143
+ module TestTree::TestTree39,1695
144
+ class TestFiberAndThreadOnNode::TestTree::TestFiberAndThreadOnNode41,1747
145
+ def create_long_depth_trees::TestTree::TestFiberAndThreadOnNode#create_long_depth_trees44,1843
146
+ def test_fiber_for_recursion::TestTree::TestFiberAndThreadOnNode#test_fiber_for_recursion59,2260
147
+ def test_thread_for_recursion::TestTree::TestFiberAndThreadOnNode#test_thread_for_recursion73,2807
148
+
149
+ test/test_tree.rb,5684
150
+ module TestTree::TestTree39,1725
151
+ class TestTreeNode::TestTree::TestTreeNode41,1777
152
+ def setup::TestTree::TestTreeNode#setup65,2610
153
+ def setup_test_tree::TestTree::TestTreeNode#setup_test_tree77,3030
154
+ def teardown::TestTree::TestTreeNode#teardown84,3180
155
+ def test_has_version_number::TestTree::TestTreeNode#test_has_version_number89,3272
156
+ def test_root_setup::TestTree::TestTreeNode#test_root_setup94,3423
157
+ def test_root::TestTree::TestTreeNode#test_root111,4473
158
+ def test_has_content_eh::TestTree::TestTreeNode#test_has_content_eh124,5023
159
+ def test_length_is_size::TestTree::TestTreeNode#test_length_is_size135,5481
160
+ def test_spaceship::TestTree::TestTreeNode#test_spaceship141,5671
161
+ def test_is_comparable::TestTree::TestTreeNode#test_is_comparable167,6454
162
+ def test_to_s::TestTree::TestTreeNode#test_to_s185,7236
163
+ def test_first_sibling::TestTree::TestTreeNode#test_first_sibling218,8954
164
+ def test_is_first_sibling_eh::TestTree::TestTreeNode#test_is_first_sibling_eh231,9682
165
+ def test_is_last_sibling_eh::TestTree::TestTreeNode#test_is_last_sibling_eh242,10165
166
+ def test_last_sibling::TestTree::TestTreeNode#test_last_sibling253,10633
167
+ def test_siblings::TestTree::TestTreeNode#test_siblings265,11287
168
+ def test_is_only_child_eh::TestTree::TestTreeNode#test_is_only_child_eh293,12210
169
+ def test_next_sibling::TestTree::TestTreeNode#test_next_sibling304,12646
170
+ def test_previous_sibling::TestTree::TestTreeNode#test_previous_sibling315,13146
171
+ def test_add::TestTree::TestTreeNode#test_add326,13675
172
+ def test_add_duplicate::TestTree::TestTreeNode#test_add_duplicate347,14357
173
+ def test_add_at_specific_position::TestTree::TestTreeNode#test_add_at_specific_position378,15292
174
+ def test_remove_bang::TestTree::TestTreeNode#test_remove_bang442,18345
175
+ def test_remove_all_bang::TestTree::TestTreeNode#test_remove_all_bang474,19308
176
+ def test_remove_from_parent_bang::TestTree::TestTreeNode#test_remove_from_parent_bang484,19614
177
+ def test_children::TestTree::TestTreeNode#test_children503,20329
178
+ def test_first_child::TestTree::TestTreeNode#test_first_child539,21918
179
+ def test_last_child::TestTree::TestTreeNode#test_last_child548,22246
180
+ def test_find::TestTree::TestTreeNode#test_find557,22562
181
+ def test_parentage::TestTree::TestTreeNode#test_parentage572,23157
182
+ def test_each::TestTree::TestTreeNode#test_each581,23489
183
+ def test_each_leaf::TestTree::TestTreeNode#test_each_leaf600,24173
184
+ def test_parent::TestTree::TestTreeNode#test_parent627,25368
185
+ def test_indexed_access::TestTree::TestTreeNode#test_indexed_access638,25787
186
+ def test_print_tree::TestTree::TestTreeNode#test_print_tree649,26160
187
+ def test_marshal_dump::TestTree::TestTreeNode#test_marshal_dump656,26320
188
+ alias test_marshal_load::TestTree::TestTreeNode#test_marshal_load698,28442
189
+ def test_collect::TestTree::TestTreeNode#test_collect701,28563
190
+ def test_freeze_tree_bang::TestTree::TestTreeNode#test_freeze_tree_bang711,28829
191
+ def test_content::TestTree::TestTreeNode#test_content725,29351
192
+ def test_depth::TestTree::TestTreeNode#test_depth733,29742
193
+ def do_deprecated_depth::TestTree::TestTreeNode#do_deprecated_depth744,30115
194
+ def test_node_height::TestTree::TestTreeNode#test_node_height762,30683
195
+ def test_node_depth::TestTree::TestTreeNode#test_node_depth787,31892
196
+ def test_level::TestTree::TestTreeNode#test_level800,32329
197
+ def test_breadth::TestTree::TestTreeNode#test_breadth815,32872
198
+ def test_breadth_each::TestTree::TestTreeNode#test_breadth_each834,33519
199
+ def test_preordered_each::TestTree::TestTreeNode#test_preordered_each875,34825
200
+ def test_postordered_each::TestTree::TestTreeNode#test_postordered_each914,36079
201
+ def test_detached_copy::TestTree::TestTreeNode#test_detached_copy953,37334
202
+ def test_detached_subtree_copy::TestTree::TestTreeNode#test_detached_subtree_copy970,38062
203
+ def test_has_children_eh::TestTree::TestTreeNode#test_has_children_eh1004,40314
204
+ def test_is_leaf_eh::TestTree::TestTreeNode#test_is_leaf_eh1010,40476
205
+ def test_is_root_eh::TestTree::TestTreeNode#test_is_root_eh1017,40682
206
+ def test_content_equals::TestTree::TestTreeNode#test_content_equals1023,40845
207
+ def test_size::TestTree::TestTreeNode#test_size1031,41110
208
+ def test_lt2::TestTree::TestTreeNode#test_lt21040,41374
209
+ def test_index::TestTree::TestTreeNode#test_index1051,41866
210
+ def test_in_degree::TestTree::TestTreeNode#test_in_degree1072,42962
211
+ def test_out_degree::TestTree::TestTreeNode#test_out_degree1083,43429
212
+ def test_json_serialization::TestTree::TestTreeNode#test_json_serialization1094,43916
213
+ def test_json_deserialization::TestTree::TestTreeNode#test_json_deserialization1118,44716
214
+ def test_json_roundtrip::TestTree::TestTreeNode#test_json_roundtrip1146,45902
215
+ def test_old_camelCase_method_names::TestTree::TestTreeNode#test_old_camelCase_method_names1162,46643
216
+ def test_integer_node_names::TestTree::TestTreeNode#test_integer_node_names1193,47711
217
+ def test_add_node_to_self_as_child::TestTree::TestTreeNode#test_add_node_to_self_as_child1224,48941
218
+ def test_single_node_becomes_leaf::TestTree::TestTreeNode#test_single_node_becomes_leaf1236,49367
219
+ def test_unique_node_names::TestTree::TestTreeNode#test_unique_node_names1248,49788
220
+ def setup_other_test_tree::TestTree::TestTreeNode#setup_other_test_tree1262,50143
221
+ def test_merge::TestTree::TestTreeNode#test_merge1290,51132
222
+ def test_merge_bang::TestTree::TestTreeNode#test_merge_bang1319,52570
data/TODO.org CHANGED
@@ -224,7 +224,10 @@
224
224
 
225
225
  * Unplanned / Not assigned to any release
226
226
  *** TODO Create a cycle-detection/validation mechanism to prevent cyclic graphs of nodes.
227
- *** TODO Revert the forced install of rubygem 2.1.11 from [[file:.travis.yml][.travis.yml]]
227
+ *** DONE Revert the forced install of rubygem 2.1.11 from [[file:.travis.yml][.travis.yml]]
228
+ CLOSED: [2014-01-12 Sun 19:06]
229
+ The issue seems to have been resolved with the 2.2.1 release of Rubygems.
230
+
228
231
  *** TODO Create a generic validation method to check for various issues in the created tree.
229
232
  *** TODO Add a FAQ document to the project.
230
233
  *** TODO The semantic of length is probably unclear. Should return the node_depth instead (or remove the method)
data/lib/tree.rb CHANGED
@@ -9,7 +9,7 @@
9
9
  # Author:: Anupam Sengupta (anupamsg@gmail.com)
10
10
  #
11
11
 
12
- # Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Anupam Sengupta
12
+ # Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Anupam Sengupta
13
13
  #
14
14
  # All rights reserved.
15
15
  #
@@ -40,11 +40,6 @@
40
40
  #
41
41
 
42
42
  require 'tree/tree_deps'
43
- require 'tree/version'
44
- require 'tree/utils/metrics_methods'
45
- require 'tree/utils/camel_case_method_handler'
46
- require 'tree/utils/json_converter'
47
- require 'tree/utils/tree_merge_handler'
48
43
 
49
44
  # This module provides a *TreeNode* class whose instances are the primary objects
50
45
  # for representing nodes in the tree.
@@ -57,8 +52,8 @@ module Tree
57
52
  # This class models the nodes for an *N-ary* tree data structure. The
58
53
  # nodes are *named*, and have a place-holder for the node data (i.e.,
59
54
  # _content_ of the node). The node names are required to be *unique*
60
- # within the tree (as the name is implicitly used as an _ID_ within
61
- # the data structure).
55
+ # amongst the sibling/peer nodes. Note that the name is implicitly
56
+ # used as an _ID_ within the data structure).
62
57
  #
63
58
  # The node's _content_ is *not* required to be unique across
64
59
  # different nodes in the tree, and can be +nil+ as well.
@@ -360,9 +355,10 @@ module Tree
360
355
  def add(child, at_index = -1)
361
356
  raise ArgumentError, "Attempting to add a nil node" unless child # Only handles the immediate child scenario
362
357
  raise ArgumentError, "Attempting add node to itself" if self == child
363
-
358
+ raise ArgumentError, "Attempting to add root as a child" if self.root == child
364
359
  # Lazy mans unique test, won't test if children of child are unique in this tree too.
365
- self.root.each { |node| raise "Child #{child.name} already added!" if node.name == child.name }
360
+ #self.root.each { |node| raise "Child #{child.name} already added!" if node.name == child.name }
361
+ self.children.each { |node| raise "Child #{child.name} already added!" if node.name == child.name }
366
362
 
367
363
  if insertion_range.include?(at_index)
368
364
  @children.insert(at_index, child)
@@ -7,7 +7,7 @@
7
7
  # Author:: Anupam Sengupta (anupamsg@gmail.com)
8
8
  #
9
9
 
10
- # Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Anupam Sengupta
10
+ # Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2014 Anupam Sengupta
11
11
  #
12
12
  # All rights reserved.
13
13
  #
@@ -39,3 +39,9 @@
39
39
 
40
40
  require 'structured_warnings'
41
41
  require 'json'
42
+
43
+ require 'tree/version'
44
+ require 'tree/utils/metrics_methods'
45
+ require 'tree/utils/camel_case_method_handler'
46
+ require 'tree/utils/json_converter'
47
+ require 'tree/utils/tree_merge_handler'
data/lib/tree/version.rb CHANGED
@@ -37,5 +37,5 @@
37
37
  #
38
38
  module Tree
39
39
  # Rubytree Package Version
40
- VERSION = '0.9.2'
40
+ VERSION = '0.9.3pre'
41
41
  end
data/test/test_tree.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # test_tree.rb - This file is part of the RubyTree package.
4
4
  #
5
- # Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Anupam Sengupta
5
+ # Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Anupam Sengupta
6
6
  #
7
7
  # All rights reserved.
8
8
  #
@@ -339,13 +339,41 @@ module TestTree
339
339
  assert_equal(5, @root.size, "Should have five nodes")
340
340
  assert_equal(2, @child3.size, "Should have two nodes")
341
341
 
342
- # Test the addition of a duplicate node (duplicate being defined as a node with the same name).
343
- assert_raise(RuntimeError) { @root.add(Tree::TreeNode.new(@child1.name)) }
344
-
345
342
  # Test the addition of a nil node.
346
343
  assert_raise(ArgumentError) { @root.add(nil) }
347
344
  end
348
345
 
346
+ # Test the addition of a duplicate node (duplicate being defined as a node with the same name).
347
+ def test_add_duplicate
348
+ # We need to allow duplicate nodes which are not *siblings*.
349
+ # Example (see https://github.com/evolve75/RubyTree/issues/24):
350
+ #
351
+ # * root
352
+ # |---+ one
353
+ # | +---> deep
354
+ # +---+ two
355
+ # +---> deep
356
+ #
357
+ # In this case, the two 'deep' nodes should not be considered duplicates
358
+
359
+ root = Tree::TreeNode.new("root")
360
+ one = Tree::TreeNode.new("one")
361
+ two = Tree::TreeNode.new("two")
362
+ deep = Tree::TreeNode.new("deep")
363
+
364
+
365
+ root << one << deep
366
+ # The same child cannot be added under any circumstance
367
+ assert_raise(RuntimeError) { root.add(Tree::TreeNode.new(one.name)) }
368
+ assert_raise(RuntimeError) { root.add(one) }
369
+
370
+ begin
371
+ root << two << deep
372
+ rescue RuntimeError => e
373
+ fail("Error! The RuntimeError should not have been thrown.")
374
+ end
375
+ end
376
+
349
377
  # Test Addition at a specific position
350
378
  def test_add_at_specific_position
351
379
  assert(!@root.has_children?, "Should not have any children")
@@ -1201,7 +1229,7 @@ module TestTree
1201
1229
 
1202
1230
  # And now a scenario where the node addition is done down the hierarchy
1203
1231
  child = Tree::TreeNode.new("child")
1204
- assert_raise(RuntimeError) { root << child << root }
1232
+ assert_raise(ArgumentError) { root << child << root }
1205
1233
  end
1206
1234
 
1207
1235
  # Test whether the tree_leaf method works correctly
@@ -1215,12 +1243,19 @@ module TestTree
1215
1243
 
1216
1244
  end
1217
1245
 
1218
- # Test if node names are really unique in the whole tree
1246
+ # Test if node names are really unique in the child array.
1247
+ # Note that this does not prevent duplicates elsewhere in the tree.
1219
1248
  def test_unique_node_names
1220
1249
  setup_test_tree
1221
1250
 
1222
1251
  assert_raise(RuntimeError) { @root << @child1 }
1223
- assert_raise(RuntimeError) { @root.first_child << @child2 }
1252
+
1253
+ begin
1254
+ @root.first_child << @child2
1255
+ rescue RuntimeError => e
1256
+ fail("No error should have been raised for adding a non-sibling duplicate.")
1257
+ end
1258
+
1224
1259
  end
1225
1260
 
1226
1261
  # Setup function to build some extra trees to play with.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubytree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anupam Sengupta
@@ -136,6 +136,7 @@ files:
136
136
  - LICENSE.md
137
137
  - README.md
138
138
  - Rakefile
139
+ - TAGS
139
140
  - TODO.org
140
141
  - examples/example_basic.rb
141
142
  - lib/rubytree.rb
@@ -189,12 +190,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
190
  version: 1.8.7
190
191
  required_rubygems_version: !ruby/object:Gem::Requirement
191
192
  requirements:
192
- - - ">="
193
+ - - ">"
193
194
  - !ruby/object:Gem::Version
194
- version: '0'
195
+ version: 1.3.1
195
196
  requirements: []
196
197
  rubyforge_project: rubytree
197
- rubygems_version: 2.2.0.rc.1
198
+ rubygems_version: 2.2.1
198
199
  signing_key:
199
200
  specification_version: 4
200
201
  summary: A generic tree data structure.