array-unique-compositing 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,16 @@
1
+
2
+ == 3/17/12
3
+
4
+ Initial release.
5
+
6
+ == 3/18/12
7
+
8
+ Added hooks for subclassing.
9
+
10
+ == 3/24/12
11
+
12
+ Added :include? implementation using @unique_keys instead of linear search.
13
+
14
+ == 6/1/12
15
+
16
+ Added :configuration_instance parameter to :initialize.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # Unique Compositing Array #
2
+
3
+ http://rubygems.org/gems/array-unique-compositing
4
+
5
+ # Description #
6
+
7
+ Provides Array::Unique::Compositing.
8
+
9
+ # Summary #
10
+
11
+ An implementation of Array that permits chaining, where children inherit changes to parent and where parent settings can be overridden in children, and that ensures inserted values are unique.
12
+
13
+ # Install #
14
+
15
+ * sudo gem install array-unique-compositing
16
+
17
+ # Usage #
18
+
19
+ ```ruby
20
+ compositing_array = Array::Unique::Compositing.new
21
+ sub_compositing_array = Array::Unique::Compositing.new( compositing_array )
22
+
23
+ compositing_array.push( :A )
24
+ # compositing_array
25
+ # => [ :A ]
26
+ # sub_compositing_array
27
+ # => [ :A ]
28
+ compositing_array.push( :A )
29
+ # compositing_array
30
+ # => [ :A ]
31
+ # sub_compositing_array
32
+ # => [ :A ]
33
+
34
+ compositing_array.delete_at( 0 )
35
+ # compositing_array
36
+ # => [ ]
37
+ # sub_compositing_array
38
+ # => [ ]
39
+
40
+ sub_compositing_array.push( :A )
41
+ # compositing_array
42
+ # => [ ]
43
+ # sub_compositing_array
44
+ # => [ :A ]
45
+ ```
46
+
47
+ # License #
48
+
49
+ (The MIT License)
50
+
51
+ Copyright (c) Asher
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining
54
+ a copy of this software and associated documentation files (the
55
+ 'Software'), to deal in the Software without restriction, including
56
+ without limitation the rights to use, copy, modify, merge, publish,
57
+ distribute, sublicense, and/or sell copies of the Software, and to
58
+ permit persons to whom the Software is furnished to do so, subject to
59
+ the following conditions:
60
+
61
+ The above copyright notice and this permission notice shall be
62
+ included in all copies or substantial portions of the Software.
63
+
64
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
65
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
66
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
67
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
68
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
69
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
70
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
File without changes
@@ -0,0 +1,2 @@
1
+
2
+ require_relative 'array/unique/compositing.rb'
@@ -0,0 +1,2 @@
1
+
2
+ require_relative '../../unique/compositing.rb'
@@ -0,0 +1,17 @@
1
+
2
+ require 'array/unique'
3
+ require 'array/compositing'
4
+ #require_relative '../../../../../hooked_objects/array-unique/lib/array-unique.rb'
5
+ #require_relative '../../../../array-compositing/lib/array/compositing.rb'
6
+
7
+ # namespaces that have to be declared ahead of time for proper load order
8
+ require_relative './namespaces'
9
+
10
+ # source file requires
11
+ require_relative './requires.rb'
12
+
13
+ class ::Array::Unique::Compositing < ::Array::Hooked
14
+
15
+ include ::Array::Unique::Compositing::ArrayInterface
16
+
17
+ end
@@ -0,0 +1,106 @@
1
+
2
+ module ::Array::Unique::Compositing::ArrayInterface
3
+
4
+ include ::Array::Unique::ArrayInterface
5
+ include ::Array::Compositing::ArrayInterface
6
+
7
+ instances_identify_as!( ::Array::Unique::Compositing )
8
+
9
+ extend ::Module::Cluster
10
+
11
+ cluster( :unique_compositing_array_interface ).before_include.cascade_to( :class ) do |hooked_instance|
12
+
13
+ hooked_instance.class_eval do
14
+
15
+ unless method_defined?( :unique_set )
16
+ alias_method :unique_set, :[]=
17
+ end
18
+
19
+ unless method_defined?( :unique_insert )
20
+ alias_method :unique_insert, :insert
21
+ end
22
+
23
+ unless method_defined?( :unique_delete_at )
24
+ alias_method :unique_delete_at, :delete_at
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ #########
32
+ # []= #
33
+ #########
34
+
35
+ def []=( local_index, object )
36
+
37
+ did_set = false
38
+
39
+ if @unique_keys.has_key?( object ) and
40
+ parent_index = @parent_index_map.parent_index( local_index ) and
41
+ @parent_composite_object[ parent_index ] == object
42
+
43
+ @parent_index_map.local_set( local_index )
44
+ else
45
+ super
46
+ end
47
+
48
+ return did_set
49
+
50
+ end
51
+
52
+ ##################################################################################################
53
+ private ######################################################################################
54
+ ##################################################################################################
55
+
56
+ ###########################
57
+ # update_for_parent_set #
58
+ ###########################
59
+
60
+ def update_for_parent_set( parent_index, object )
61
+
62
+ called_super = false
63
+
64
+ unless @unique_keys.has_key?( object )
65
+ @unique_keys[ object ] = true
66
+ called_super = true
67
+ super
68
+ end
69
+
70
+ return called_super
71
+
72
+ end
73
+
74
+ ##############################
75
+ # update_for_parent_insert #
76
+ ##############################
77
+
78
+ def update_for_parent_insert( parent_index, object )
79
+
80
+ called_super = false
81
+
82
+ unless @unique_keys.has_key?( object )
83
+ @unique_keys[ object ] = true
84
+ called_super = true
85
+ super
86
+ end
87
+
88
+ return called_super
89
+
90
+ end
91
+
92
+ #################################
93
+ # update_for_parent_delete_at #
94
+ #################################
95
+
96
+ def update_for_parent_delete_at( parent_index, object )
97
+
98
+ if did_delete = super
99
+ @unique_keys.delete( object )
100
+ end
101
+
102
+ return did_delete
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,5 @@
1
+
2
+ class ::Array::Unique < ::Array::Hooked
3
+ class Compositing < ::Array::Hooked
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+
2
+ require_relative 'compositing/array_interface.rb'
@@ -0,0 +1,1094 @@
1
+
2
+ require_relative '../../../lib/array/unique/compositing.rb'
3
+
4
+ describe ::Array::Unique::Compositing do
5
+
6
+ ################
7
+ # initialize #
8
+ ################
9
+
10
+ it 'can add initialize with an ancestor, inheriting its values and linking to it as a child' do
11
+
12
+ cascading_composite_array = ::Array::Unique::Compositing.new
13
+
14
+ cascading_composite_array.instance_variable_get( :@parent_composite_object ).should == nil
15
+ cascading_composite_array.should == []
16
+ cascading_composite_array.push( :A, :B, :C, :D )
17
+
18
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
19
+ sub_cascading_composite_array.instance_variable_get( :@parent_composite_object ).should == cascading_composite_array
20
+ sub_cascading_composite_array.should == [ :A, :B, :C, :D ]
21
+
22
+ end
23
+
24
+ #########
25
+ # []= #
26
+ #########
27
+
28
+ it 'can add elements' do
29
+
30
+ cascading_composite_array = ::Array::Unique::Compositing.new
31
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
32
+
33
+ cascading_composite_array[ 0 ] = :A
34
+ cascading_composite_array.should == [ :A ]
35
+ sub_cascading_composite_array.should == [ :A ]
36
+
37
+ cascading_composite_array[ 1 ] = :B
38
+ cascading_composite_array.should == [ :A, :B ]
39
+ sub_cascading_composite_array.should == [ :A, :B ]
40
+
41
+ sub_cascading_composite_array[ 0 ] = :C
42
+ cascading_composite_array.should == [ :A, :B ]
43
+ sub_cascading_composite_array.should == [ :C, :B ]
44
+
45
+ sub_cascading_composite_array[ 0 ] = :B
46
+ cascading_composite_array.should == [ :A, :B ]
47
+ sub_cascading_composite_array.should == [ :C, :B ]
48
+
49
+ sub_cascading_composite_array[ 2 ] = :C
50
+ cascading_composite_array.should == [ :A, :B ]
51
+ sub_cascading_composite_array.should == [ :C, :B ]
52
+
53
+ cascading_composite_array[ 2 ] = :D
54
+ cascading_composite_array.should == [ :A, :B, :D ]
55
+ sub_cascading_composite_array.should == [ :C, :B, :D ]
56
+
57
+ end
58
+
59
+ ############
60
+ # insert #
61
+ ############
62
+
63
+ it 'can insert elements' do
64
+
65
+ cascading_composite_array = ::Array::Unique::Compositing.new
66
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
67
+
68
+ cascading_composite_array.insert( 3, :D )
69
+ cascading_composite_array.should == [ nil, :D ]
70
+ sub_cascading_composite_array.should == [ nil, :D ]
71
+
72
+ cascading_composite_array.insert( 1, :B )
73
+ cascading_composite_array.should == [ nil, :B, :D ]
74
+ sub_cascading_composite_array.should == [ nil, :B, :D ]
75
+
76
+ cascading_composite_array.insert( 2, :C )
77
+ cascading_composite_array.should == [ nil, :B, :C, :D ]
78
+ sub_cascading_composite_array.should == [ nil, :B, :C, :D ]
79
+
80
+ sub_cascading_composite_array.insert( 0, :E )
81
+ cascading_composite_array.should == [ nil, :B, :C, :D ]
82
+ sub_cascading_composite_array.should == [ :E, nil, :B, :C, :D ]
83
+
84
+ sub_cascading_composite_array.insert( 4, :F )
85
+ cascading_composite_array.should == [ nil, :B, :C, :D ]
86
+ sub_cascading_composite_array.should == [ :E, nil, :B, :C, :F, :D ]
87
+
88
+ end
89
+
90
+ ##########
91
+ # push #
92
+ # << #
93
+ ##########
94
+
95
+ it 'can add elements' do
96
+
97
+ cascading_composite_array = ::Array::Unique::Compositing.new
98
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
99
+
100
+ cascading_composite_array << :A
101
+ cascading_composite_array.should == [ :A ]
102
+ sub_cascading_composite_array.should == [ :A ]
103
+
104
+ cascading_composite_array << :B
105
+ cascading_composite_array.should == [ :A, :B ]
106
+ sub_cascading_composite_array.should == [ :A, :B ]
107
+
108
+ sub_cascading_composite_array << :C
109
+ cascading_composite_array.should == [ :A, :B ]
110
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
111
+
112
+ sub_cascading_composite_array << :B
113
+ cascading_composite_array.should == [ :A, :B ]
114
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
115
+
116
+ end
117
+
118
+ ############
119
+ # concat #
120
+ # + #
121
+ ############
122
+
123
+ it 'can add elements' do
124
+
125
+ # NOTE: this breaks + by causing it to modify the array like +=
126
+ # The alternative was worse.
127
+
128
+ cascading_composite_array = ::Array::Unique::Compositing.new
129
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
130
+
131
+ cascading_composite_array.concat( [ :A ] )
132
+ cascading_composite_array.should == [ :A ]
133
+ sub_cascading_composite_array.should == [ :A ]
134
+
135
+ cascading_composite_array += [ :B ]
136
+ cascading_composite_array.should == [ :A, :B ]
137
+ sub_cascading_composite_array.should == [ :A, :B ]
138
+
139
+ sub_cascading_composite_array.concat( [ :C ] )
140
+ cascading_composite_array.should == [ :A, :B ]
141
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
142
+
143
+ sub_cascading_composite_array += [ :B ]
144
+ cascading_composite_array.should == [ :A, :B ]
145
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
146
+
147
+ end
148
+
149
+ ####################
150
+ # delete_objects #
151
+ ####################
152
+
153
+ it 'can delete multiple elements' do
154
+
155
+ cascading_composite_array = ::Array::Unique::Compositing.new
156
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
157
+
158
+ cascading_composite_array += [ :A, :B ]
159
+ cascading_composite_array.should == [ :A, :B ]
160
+ sub_cascading_composite_array.should == [ :A, :B ]
161
+
162
+ cascading_composite_array.delete_objects( :A, :B )
163
+ cascading_composite_array.should == [ ]
164
+ sub_cascading_composite_array.should == [ ]
165
+
166
+ sub_cascading_composite_array += [ :B, :C, :D ]
167
+ cascading_composite_array.should == [ ]
168
+ sub_cascading_composite_array.should == [ :B, :C, :D ]
169
+
170
+ sub_cascading_composite_array.delete_objects( :C, :B )
171
+ cascading_composite_array.should == [ ]
172
+ sub_cascading_composite_array.should == [ :D ]
173
+
174
+ end
175
+
176
+ #######
177
+ # - #
178
+ #######
179
+
180
+ it 'can exclude elements' do
181
+
182
+ cascading_composite_array = ::Array::Unique::Compositing.new
183
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
184
+
185
+ cascading_composite_array.push( :A )
186
+ cascading_composite_array.should == [ :A ]
187
+ sub_cascading_composite_array.should == [ :A ]
188
+
189
+ cascading_composite_array -= [ :A ]
190
+ cascading_composite_array.should == [ ]
191
+ sub_cascading_composite_array.should == [ ]
192
+
193
+ cascading_composite_array.push( :B )
194
+ cascading_composite_array.should == [ :B ]
195
+ sub_cascading_composite_array.should == [ :B ]
196
+
197
+ sub_cascading_composite_array.push( :C )
198
+ cascading_composite_array.should == [ :B ]
199
+ sub_cascading_composite_array.should == [ :B, :C ]
200
+
201
+ sub_cascading_composite_array -= [ :B ]
202
+ cascading_composite_array.should == [ :B ]
203
+ sub_cascading_composite_array.should == [ :C ]
204
+
205
+ end
206
+
207
+ ############
208
+ # delete #
209
+ ############
210
+
211
+ it 'can delete elements' do
212
+
213
+ cascading_composite_array = ::Array::Unique::Compositing.new
214
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
215
+
216
+ cascading_composite_array.push( :A )
217
+ cascading_composite_array.should == [ :A ]
218
+ sub_cascading_composite_array.should == [ :A ]
219
+
220
+ cascading_composite_array.delete( :A )
221
+ cascading_composite_array.should == [ ]
222
+ sub_cascading_composite_array.should == [ ]
223
+
224
+ cascading_composite_array.push( :B )
225
+ cascading_composite_array.should == [ :B ]
226
+ sub_cascading_composite_array.should == [ :B ]
227
+
228
+ sub_cascading_composite_array.push( :C )
229
+ cascading_composite_array.should == [ :B ]
230
+ sub_cascading_composite_array.should == [ :B, :C ]
231
+
232
+ sub_cascading_composite_array.delete( :B )
233
+ cascading_composite_array.should == [ :B ]
234
+ sub_cascading_composite_array.should == [ :C ]
235
+
236
+ end
237
+
238
+ ###############
239
+ # delete_at #
240
+ ###############
241
+
242
+ it 'can delete by indexes' do
243
+
244
+ cascading_composite_array = ::Array::Unique::Compositing.new
245
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
246
+
247
+ cascading_composite_array.push( :A )
248
+ cascading_composite_array.should == [ :A ]
249
+ sub_cascading_composite_array.should == [ :A ]
250
+
251
+ cascading_composite_array.delete_at( 0 )
252
+ cascading_composite_array.should == [ ]
253
+ sub_cascading_composite_array.should == [ ]
254
+
255
+ cascading_composite_array.push( :B )
256
+ cascading_composite_array.should == [ :B ]
257
+ sub_cascading_composite_array.should == [ :B ]
258
+
259
+ sub_cascading_composite_array.push( :C )
260
+ cascading_composite_array.should == [ :B ]
261
+ sub_cascading_composite_array.should == [ :B, :C ]
262
+
263
+ sub_cascading_composite_array.delete_at( 0 )
264
+ cascading_composite_array.should == [ :B ]
265
+ sub_cascading_composite_array.should == [ :C ]
266
+
267
+ end
268
+
269
+ #######################
270
+ # delete_at_indexes #
271
+ #######################
272
+
273
+ it 'can delete by indexes' do
274
+
275
+ cascading_composite_array = ::Array::Unique::Compositing.new
276
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
277
+
278
+ cascading_composite_array.push( :A, :B, :C )
279
+ cascading_composite_array.should == [ :A, :B, :C ]
280
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
281
+
282
+ cascading_composite_array.delete_at_indexes( 0, 1 )
283
+ cascading_composite_array.should == [ :C ]
284
+ sub_cascading_composite_array.should == [ :C ]
285
+
286
+ sub_cascading_composite_array.push( :C, :B )
287
+ cascading_composite_array.should == [ :C ]
288
+ sub_cascading_composite_array.should == [ :C, :B ]
289
+
290
+ sub_cascading_composite_array.delete_at_indexes( 0, 1, 2 )
291
+ cascading_composite_array.should == [ :C ]
292
+ sub_cascading_composite_array.should == [ ]
293
+
294
+ end
295
+
296
+ ###############
297
+ # delete_if #
298
+ ###############
299
+
300
+ it 'can delete by block' do
301
+
302
+ cascading_composite_array = ::Array::Unique::Compositing.new
303
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
304
+
305
+ cascading_composite_array.push( :A, :B, :C )
306
+ cascading_composite_array.should == [ :A, :B, :C ]
307
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
308
+ cascading_composite_array.delete_if do |object|
309
+ object != :C
310
+ end
311
+ cascading_composite_array.should == [ :C ]
312
+ sub_cascading_composite_array.should == [ :C ]
313
+
314
+ sub_cascading_composite_array.push( :C, :B )
315
+ cascading_composite_array.should == [ :C ]
316
+ sub_cascading_composite_array.should == [ :C, :B ]
317
+ sub_cascading_composite_array.delete_if do |object|
318
+ object != nil
319
+ end
320
+ sub_cascading_composite_array.should == [ ]
321
+ cascading_composite_array.should == [ :C ]
322
+
323
+ cascading_composite_array.delete_if.is_a?( Enumerator ).should == true
324
+
325
+ end
326
+
327
+ #############
328
+ # keep_if #
329
+ #############
330
+
331
+ it 'can keep by block' do
332
+
333
+ cascading_composite_array = ::Array::Unique::Compositing.new
334
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
335
+
336
+ cascading_composite_array.push( :A, :B, :C )
337
+ cascading_composite_array.should == [ :A, :B, :C ]
338
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
339
+ cascading_composite_array.keep_if do |object|
340
+ object == :C
341
+ end
342
+ cascading_composite_array.should == [ :C ]
343
+ sub_cascading_composite_array.should == [ :C ]
344
+
345
+ sub_cascading_composite_array.push( :C, :B )
346
+ cascading_composite_array.should == [ :C ]
347
+ sub_cascading_composite_array.should == [ :C, :B ]
348
+ sub_cascading_composite_array.keep_if do |object|
349
+ object == nil
350
+ end
351
+ cascading_composite_array.should == [ :C ]
352
+ sub_cascading_composite_array.should == [ ]
353
+
354
+ end
355
+
356
+ ##############
357
+ # compact! #
358
+ ##############
359
+
360
+ it 'can compact' do
361
+
362
+ cascading_composite_array = ::Array::Unique::Compositing.new
363
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
364
+
365
+ cascading_composite_array.push( :A, nil, :B, nil, :C, nil )
366
+ cascading_composite_array.should == [ :A, nil, :B, :C ]
367
+ sub_cascading_composite_array.should == [ :A, nil, :B, :C ]
368
+ cascading_composite_array.compact!
369
+ cascading_composite_array.should == [ :A, :B, :C ]
370
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
371
+
372
+ sub_cascading_composite_array.push( nil, nil, :D )
373
+ cascading_composite_array.should == [ :A, :B, :C ]
374
+ sub_cascading_composite_array.should == [ :A, :B, :C, nil, :D ]
375
+ sub_cascading_composite_array.compact!
376
+ cascading_composite_array.should == [ :A, :B, :C ]
377
+ sub_cascading_composite_array.should == [ :A, :B, :C, :D ]
378
+
379
+ end
380
+
381
+ ##############
382
+ # flatten! #
383
+ ##############
384
+
385
+ it 'can flatten' do
386
+
387
+ cascading_composite_array = ::Array::Unique::Compositing.new
388
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
389
+
390
+ cascading_composite_array.push( :A, [ :F_A, :F_B ], :B, [ :F_C ], :C, [ :F_D ], [ :F_E ] )
391
+ cascading_composite_array.should == [ :A, [ :F_A, :F_B ], :B, [ :F_C ], :C, [ :F_D ], [ :F_E ] ]
392
+ sub_cascading_composite_array.should == [ :A, [ :F_A, :F_B ], :B, [ :F_C ], :C, [ :F_D ], [ :F_E ] ]
393
+ cascading_composite_array.flatten!
394
+ cascading_composite_array.should == [ :A, :F_A, :F_B, :B, :F_C, :C, :F_D, :F_E ]
395
+
396
+ sub_cascading_composite_array.should == [ :A, :F_A, :F_B, :B, :F_C, :C, :F_D, :F_E ]
397
+
398
+ sub_cascading_composite_array.push( [ :F_F, :F_G ], :D, [ :F_H ] )
399
+ cascading_composite_array.should == [ :A, :F_A, :F_B, :B, :F_C, :C, :F_D, :F_E ]
400
+ sub_cascading_composite_array.should == [ :A, :F_A, :F_B, :B, :F_C, :C, :F_D, :F_E, [ :F_F, :F_G ], :D, [ :F_H ] ]
401
+ sub_cascading_composite_array.flatten!
402
+ cascading_composite_array.should == [ :A, :F_A, :F_B, :B, :F_C, :C, :F_D, :F_E ]
403
+ sub_cascading_composite_array.should == [ :A, :F_A, :F_B, :B, :F_C, :C, :F_D, :F_E, :F_F, :F_G, :D, :F_H ]
404
+
405
+ end
406
+
407
+ #############
408
+ # reject! #
409
+ #############
410
+
411
+ it 'can reject' do
412
+
413
+ cascading_composite_array = ::Array::Unique::Compositing.new
414
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
415
+
416
+ cascading_composite_array.push( :A, :B, :C )
417
+ cascading_composite_array.should == [ :A, :B, :C ]
418
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
419
+ cascading_composite_array.reject! do |object|
420
+ object != :C
421
+ end
422
+ cascading_composite_array.should == [ :C ]
423
+ sub_cascading_composite_array.should == [ :C ]
424
+
425
+ sub_cascading_composite_array.push( :C, :B )
426
+ cascading_composite_array.should == [ :C ]
427
+ sub_cascading_composite_array.should == [ :C, :B ]
428
+ sub_cascading_composite_array.reject! do |object|
429
+ object != nil
430
+ end
431
+ sub_cascading_composite_array.should == [ ]
432
+ cascading_composite_array.should == [ :C ]
433
+
434
+ cascading_composite_array.reject!.is_a?( Enumerator ).should == true
435
+
436
+ end
437
+
438
+ #############
439
+ # replace #
440
+ #############
441
+
442
+ it 'can replace self' do
443
+
444
+ cascading_composite_array = ::Array::Unique::Compositing.new
445
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
446
+
447
+ cascading_composite_array.push( :A, :B, :C )
448
+ cascading_composite_array.should == [ :A, :B, :C ]
449
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
450
+ cascading_composite_array.replace( [ :D, :E, :F ] )
451
+ cascading_composite_array.should == [ :D, :E, :F ]
452
+ sub_cascading_composite_array.should == [ :D, :E, :F ]
453
+
454
+ cascading_composite_array.should == [ :D, :E, :F ]
455
+ sub_cascading_composite_array.should == [ :D, :E, :F ]
456
+ sub_cascading_composite_array.replace( [ :G, :H, :I ] )
457
+ cascading_composite_array.should == [ :D, :E, :F ]
458
+ sub_cascading_composite_array.should == [ :G, :H, :I ]
459
+
460
+ end
461
+
462
+ ##############
463
+ # reverse! #
464
+ ##############
465
+
466
+ it 'can reverse self' do
467
+
468
+ cascading_composite_array = ::Array::Unique::Compositing.new
469
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
470
+
471
+ cascading_composite_array.push( :A, :B, :C )
472
+ cascading_composite_array.should == [ :A, :B, :C ]
473
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
474
+ cascading_composite_array.reverse!
475
+ cascading_composite_array.should == [ :C, :B, :A ]
476
+ sub_cascading_composite_array.should == [ :C, :B, :A ]
477
+
478
+ cascading_composite_array.should == [ :C, :B, :A ]
479
+ sub_cascading_composite_array.should == [ :C, :B, :A ]
480
+ sub_cascading_composite_array.reverse!
481
+ cascading_composite_array.should == [ :C, :B, :A ]
482
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
483
+
484
+ end
485
+
486
+ #############
487
+ # rotate! #
488
+ #############
489
+
490
+ it 'can rotate self' do
491
+
492
+ cascading_composite_array = ::Array::Unique::Compositing.new
493
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
494
+
495
+ cascading_composite_array.push( :A, :B, :C )
496
+ cascading_composite_array.should == [ :A, :B, :C ]
497
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
498
+
499
+ cascading_composite_array.rotate!
500
+ cascading_composite_array.should == [ :B, :C, :A ]
501
+ sub_cascading_composite_array.should == [ :B, :C, :A ]
502
+
503
+ cascading_composite_array.rotate!( -1 )
504
+ cascading_composite_array.should == [ :A, :B, :C ]
505
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
506
+
507
+ sub_cascading_composite_array.rotate!( 2 )
508
+ cascading_composite_array.should == [ :A, :B, :C ]
509
+ sub_cascading_composite_array.should == [ :C, :A, :B ]
510
+
511
+ end
512
+
513
+ #############
514
+ # select! #
515
+ #############
516
+
517
+ it 'can keep by select' do
518
+
519
+ cascading_composite_array = ::Array::Unique::Compositing.new
520
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
521
+
522
+ cascading_composite_array.push( :A, :B, :C )
523
+ cascading_composite_array.should == [ :A, :B, :C ]
524
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
525
+ cascading_composite_array.select! do |object|
526
+ object == :C
527
+ end
528
+ cascading_composite_array.should == [ :C ]
529
+ sub_cascading_composite_array.should == [ :C ]
530
+
531
+ sub_cascading_composite_array.push( :C, :B )
532
+ cascading_composite_array.should == [ :C ]
533
+ sub_cascading_composite_array.should == [ :C, :B ]
534
+ sub_cascading_composite_array.select! do |object|
535
+ object == nil
536
+ end
537
+ cascading_composite_array.should == [ :C ]
538
+ sub_cascading_composite_array.should == [ ]
539
+
540
+ cascading_composite_array.select!.is_a?( Enumerator ).should == true
541
+
542
+ end
543
+
544
+ ##############
545
+ # shuffle! #
546
+ ##############
547
+
548
+ it 'can shuffle self' do
549
+
550
+ cascading_composite_array = ::Array::Unique::Compositing.new
551
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
552
+
553
+ cascading_composite_array.push( :A, :B, :C )
554
+ cascading_composite_array.should == [ :A, :B, :C ]
555
+ sub_cascading_composite_array.should == cascading_composite_array
556
+
557
+ prior_version = cascading_composite_array.dup
558
+ attempts = [ ]
559
+ 50.times do
560
+ cascading_composite_array.shuffle!
561
+ attempts.push( cascading_composite_array == prior_version )
562
+ prior_version = cascading_composite_array.dup
563
+ end
564
+ attempts_correct = attempts.select { |member| member == false }.count
565
+ ( attempts_correct >= 10 ).should == true
566
+ sub_cascading_composite_array.should == cascading_composite_array
567
+ first_shuffle_version = cascading_composite_array
568
+
569
+ cascading_composite_array.should == first_shuffle_version
570
+ attempts = [ ]
571
+ 50.times do
572
+ sub_cascading_composite_array.shuffle!
573
+ attempts.push( sub_cascading_composite_array == cascading_composite_array )
574
+ prior_version = cascading_composite_array.dup
575
+ end
576
+ attempts_correct = attempts.select { |member| member == false }.count
577
+ ( attempts_correct >= 10 ).should == true
578
+
579
+ end
580
+
581
+ ##############
582
+ # collect! #
583
+ # map! #
584
+ ##############
585
+
586
+ it 'can replace by collect/map' do
587
+
588
+ cascading_composite_array = ::Array::Unique::Compositing.new
589
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
590
+
591
+ cascading_composite_array.push( :A, :B, :C )
592
+ cascading_composite_array.should == [ :A, :B, :C ]
593
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
594
+ cascading_composite_array.collect! do |object|
595
+ :C
596
+ end
597
+ cascading_composite_array.should == [ :C ]
598
+ sub_cascading_composite_array.should == [ :C ]
599
+
600
+ sub_cascading_composite_array.collect! do |object|
601
+ :A
602
+ end
603
+ cascading_composite_array.should == [ :C ]
604
+ sub_cascading_composite_array.should == [ :A ]
605
+
606
+ cascading_composite_array.collect!.is_a?( Enumerator ).should == true
607
+
608
+ end
609
+
610
+ ###########
611
+ # sort! #
612
+ ###########
613
+
614
+ it 'can replace by collect/map' do
615
+
616
+ cascading_composite_array = ::Array::Unique::Compositing.new
617
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
618
+
619
+ cascading_composite_array.push( :A, :B, :C )
620
+ cascading_composite_array.should == [ :A, :B, :C ]
621
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
622
+ cascading_composite_array.sort! do |a, b|
623
+ if a < b
624
+ 1
625
+ elsif a > b
626
+ -1
627
+ elsif a == b
628
+ 0
629
+ end
630
+ end
631
+ cascading_composite_array.should == [ :C, :B, :A ]
632
+ sub_cascading_composite_array.should == [ :C, :B, :A ]
633
+
634
+ sub_cascading_composite_array.sort! do |a, b|
635
+ if a < b
636
+ -1
637
+ elsif a > b
638
+ 1
639
+ elsif a == b
640
+ 0
641
+ end
642
+ end
643
+ cascading_composite_array.should == [ :C, :B, :A ]
644
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
645
+
646
+ cascading_composite_array.sort!
647
+ cascading_composite_array.should == [ :A, :B, :C ]
648
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
649
+
650
+ end
651
+
652
+ ##############
653
+ # sort_by! #
654
+ ##############
655
+
656
+ it 'can replace by collect/map' do
657
+
658
+ cascading_composite_array = ::Array::Unique::Compositing.new
659
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
660
+
661
+ cascading_composite_array.push( :A, :B, :C )
662
+ cascading_composite_array.should == [ :A, :B, :C ]
663
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
664
+ cascading_composite_array.sort_by! do |object|
665
+ case object
666
+ when :A
667
+ :B
668
+ when :B
669
+ :A
670
+ when :C
671
+ :C
672
+ end
673
+ end
674
+ cascading_composite_array.should == [ :B, :A, :C ]
675
+ sub_cascading_composite_array.should == [ :B, :A, :C ]
676
+
677
+ sub_cascading_composite_array.sort_by! do |object|
678
+ case object
679
+ when :A
680
+ :C
681
+ when :B
682
+ :B
683
+ when :C
684
+ :A
685
+ end
686
+ end
687
+ cascading_composite_array.should == [ :B, :A, :C ]
688
+ sub_cascading_composite_array.should == [ :C, :B, :A ]
689
+
690
+ cascading_composite_array.sort_by!.is_a?( Enumerator ).should == true
691
+
692
+ end
693
+
694
+ ###########
695
+ # uniq! #
696
+ ###########
697
+
698
+ it 'can remove non-unique elements' do
699
+
700
+ cascading_composite_array = ::Array::Unique::Compositing.new
701
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
702
+
703
+ cascading_composite_array.push( :A, :B, :C, :C, :C, :B, :A )
704
+ cascading_composite_array.should == [ :A, :B, :C ]
705
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
706
+ cascading_composite_array.uniq!
707
+ cascading_composite_array.should == [ :A, :B, :C ]
708
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
709
+
710
+ sub_cascading_composite_array.push( :C, :B )
711
+ cascading_composite_array.should == [ :A, :B, :C ]
712
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
713
+ sub_cascading_composite_array.uniq!
714
+ cascading_composite_array.should == [ :A, :B, :C ]
715
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
716
+
717
+ end
718
+
719
+ #############
720
+ # unshift #
721
+ #############
722
+
723
+ it 'can unshift onto the first element' do
724
+
725
+ cascading_composite_array = ::Array::Unique::Compositing.new
726
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
727
+
728
+ cascading_composite_array += :A
729
+ cascading_composite_array.should == [ :A ]
730
+ sub_cascading_composite_array.should == [ :A ]
731
+
732
+ cascading_composite_array.unshift( :B )
733
+ cascading_composite_array.should == [ :B, :A ]
734
+ sub_cascading_composite_array.should == [ :B, :A ]
735
+
736
+ sub_cascading_composite_array.unshift( :C )
737
+ cascading_composite_array.should == [ :B, :A ]
738
+ sub_cascading_composite_array.should == [ :C, :B, :A ]
739
+
740
+ end
741
+
742
+ #########
743
+ # pop #
744
+ #########
745
+
746
+ it 'can pop the final element' do
747
+
748
+ cascading_composite_array = ::Array::Unique::Compositing.new
749
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
750
+
751
+ cascading_composite_array += :A
752
+ cascading_composite_array.should == [ :A ]
753
+ sub_cascading_composite_array.should == [ :A ]
754
+
755
+ cascading_composite_array.pop.should == :A
756
+ cascading_composite_array.should == [ ]
757
+ sub_cascading_composite_array.should == [ ]
758
+
759
+ cascading_composite_array += :B
760
+ cascading_composite_array.should == [ :B ]
761
+ sub_cascading_composite_array.should == [ :B ]
762
+
763
+ sub_cascading_composite_array += :C
764
+ cascading_composite_array.should == [ :B ]
765
+ sub_cascading_composite_array.should == [ :B, :C ]
766
+ sub_cascading_composite_array.pop.should == :C
767
+ cascading_composite_array.should == [ :B ]
768
+ sub_cascading_composite_array.should == [ :B ]
769
+
770
+ end
771
+
772
+ ###########
773
+ # shift #
774
+ ###########
775
+
776
+ it 'can shift the first element' do
777
+
778
+ cascading_composite_array = ::Array::Unique::Compositing.new
779
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
780
+
781
+ cascading_composite_array += :A
782
+ cascading_composite_array.should == [ :A ]
783
+ sub_cascading_composite_array.should == [ :A ]
784
+
785
+ cascading_composite_array.shift.should == :A
786
+ cascading_composite_array.should == [ ]
787
+ sub_cascading_composite_array.should == [ ]
788
+
789
+ cascading_composite_array += :B
790
+ cascading_composite_array.should == [ :B ]
791
+ sub_cascading_composite_array.should == [ :B ]
792
+
793
+ sub_cascading_composite_array += :C
794
+ cascading_composite_array.should == [ :B ]
795
+ sub_cascading_composite_array.should == [ :B, :C ]
796
+ sub_cascading_composite_array.shift.should == :B
797
+ cascading_composite_array.should == [ :B ]
798
+ sub_cascading_composite_array.should == [ :C ]
799
+
800
+ end
801
+
802
+ ############
803
+ # slice! #
804
+ ############
805
+
806
+ it 'can slice elements' do
807
+
808
+ cascading_composite_array = ::Array::Unique::Compositing.new
809
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
810
+
811
+ cascading_composite_array += :A
812
+ cascading_composite_array.should == [ :A ]
813
+ sub_cascading_composite_array.should == [ :A ]
814
+
815
+ cascading_composite_array.slice!( 0, 1 ).should == [ :A ]
816
+ cascading_composite_array.should == [ ]
817
+ sub_cascading_composite_array.should == [ ]
818
+
819
+ cascading_composite_array += :B
820
+ cascading_composite_array.should == [ :B ]
821
+ sub_cascading_composite_array.should == [ :B ]
822
+
823
+ sub_cascading_composite_array += :C
824
+ cascading_composite_array.should == [ :B ]
825
+ sub_cascading_composite_array.should == [ :B, :C ]
826
+
827
+ sub_cascading_composite_array.slice!( 0, 1 ).should == [ :B ]
828
+ cascading_composite_array.should == [ :B ]
829
+ sub_cascading_composite_array.should == [ :C ]
830
+
831
+ end
832
+
833
+ ###########
834
+ # clear #
835
+ ###########
836
+
837
+ it 'can clear, causing present elements to be excluded' do
838
+
839
+ cascading_composite_array = ::Array::Unique::Compositing.new
840
+ sub_cascading_composite_array = ::Array::Unique::Compositing.new( cascading_composite_array )
841
+
842
+ cascading_composite_array += :A
843
+ cascading_composite_array.should == [ :A ]
844
+ sub_cascading_composite_array.should == [ :A ]
845
+
846
+ cascading_composite_array.clear
847
+ cascading_composite_array.should == [ ]
848
+ sub_cascading_composite_array.should == [ ]
849
+
850
+ cascading_composite_array += :B
851
+ cascading_composite_array.should == [ :B ]
852
+ sub_cascading_composite_array.should == [ :B ]
853
+
854
+ sub_cascading_composite_array += :C
855
+ cascading_composite_array.should == [ :B ]
856
+ sub_cascading_composite_array.should == [ :B, :C ]
857
+
858
+ sub_cascading_composite_array.clear
859
+ cascading_composite_array.should == [ :B ]
860
+ sub_cascading_composite_array.should == [ ]
861
+
862
+ end
863
+
864
+ ##################
865
+ # pre_set_hook #
866
+ ##################
867
+
868
+ it 'has a hook that is called before setting a value; return value is used in place of object' do
869
+
870
+ class ::Array::Unique::Compositing::SubMockPreSet < ::Array::Unique::Compositing
871
+
872
+ def pre_set_hook( index, object, is_insert = false )
873
+ return :some_other_value
874
+ end
875
+
876
+ end
877
+
878
+ cascading_composite_array = ::Array::Unique::Compositing::SubMockPreSet.new
879
+
880
+ cascading_composite_array.push( :some_value )
881
+
882
+ cascading_composite_array.should == [ :some_other_value ]
883
+
884
+ end
885
+
886
+ ###################
887
+ # post_set_hook #
888
+ ###################
889
+
890
+ it 'has a hook that is called after setting a value' do
891
+
892
+ class ::Array::Unique::Compositing::SubMockPostSet < ::Array::Unique::Compositing
893
+
894
+ def post_set_hook( index, object, is_insert = false )
895
+ return :some_other_value
896
+ end
897
+
898
+ end
899
+
900
+ cascading_composite_array = ::Array::Unique::Compositing::SubMockPostSet.new
901
+
902
+ cascading_composite_array.push( :some_value ).should == [ :some_other_value ]
903
+
904
+ cascading_composite_array.should == [ :some_value ]
905
+
906
+ end
907
+
908
+ ##################
909
+ # pre_get_hook #
910
+ ##################
911
+
912
+ it 'has a hook that is called before getting a value; if return value is false, get does not occur' do
913
+
914
+ class ::Array::Unique::Compositing::SubMockPreGet < ::Array::Unique::Compositing
915
+
916
+ def pre_get_hook( index )
917
+ return false
918
+ end
919
+
920
+ end
921
+
922
+ cascading_composite_array = ::Array::Unique::Compositing::SubMockPreGet.new
923
+
924
+ cascading_composite_array.push( :some_value )
925
+ cascading_composite_array[ 0 ].should == nil
926
+
927
+ cascading_composite_array.should == [ :some_value ]
928
+
929
+ end
930
+
931
+ ###################
932
+ # post_get_hook #
933
+ ###################
934
+
935
+ it 'has a hook that is called after getting a value' do
936
+
937
+ class ::Array::Unique::Compositing::SubMockPostGet < ::Array::Unique::Compositing
938
+
939
+ def post_get_hook( index, object )
940
+ return :some_other_value
941
+ end
942
+
943
+ end
944
+
945
+ cascading_composite_array = ::Array::Unique::Compositing::SubMockPostGet.new
946
+
947
+ cascading_composite_array.push( :some_value )
948
+ cascading_composite_array[ 0 ].should == :some_other_value
949
+
950
+ cascading_composite_array.should == [ :some_value ]
951
+
952
+ end
953
+
954
+ #####################
955
+ # pre_delete_hook #
956
+ #####################
957
+
958
+ it 'has a hook that is called before deleting an index; if return value is false, delete does not occur' do
959
+
960
+ class ::Array::Unique::Compositing::SubMockPreDelete < ::Array::Unique::Compositing
961
+
962
+ def pre_delete_hook( index )
963
+ return false
964
+ end
965
+
966
+ end
967
+
968
+ cascading_composite_array = ::Array::Unique::Compositing::SubMockPreDelete.new
969
+
970
+ cascading_composite_array.push( :some_value )
971
+ cascading_composite_array.delete_at( 0 )
972
+
973
+ cascading_composite_array.should == [ :some_value ]
974
+
975
+ end
976
+
977
+ ######################
978
+ # post_delete_hook #
979
+ ######################
980
+
981
+ it 'has a hook that is called after deleting an index' do
982
+
983
+ class ::Array::Unique::Compositing::SubMockPostDelete < ::Array::Unique::Compositing
984
+
985
+ def post_delete_hook( index, object )
986
+ return :some_other_value
987
+ end
988
+
989
+ end
990
+
991
+ cascading_composite_array = ::Array::Unique::Compositing::SubMockPostDelete.new
992
+
993
+ cascading_composite_array.push( :some_value )
994
+ cascading_composite_array.delete_at( 0 ).should == :some_other_value
995
+
996
+ cascading_composite_array.should == [ ]
997
+
998
+ end
999
+
1000
+ ########################
1001
+ # child_pre_set_hook #
1002
+ ########################
1003
+
1004
+ it 'has a hook that is called before setting a value that has been passed by a parent; return value is used in place of object' do
1005
+
1006
+ class ::Array::Unique::Compositing::SubMockChildPreSet < ::Array::Unique::Compositing
1007
+
1008
+ def child_pre_set_hook( index, object, is_insert = false )
1009
+ return :some_other_value
1010
+ end
1011
+
1012
+ end
1013
+
1014
+ cascading_composite_array = ::Array::Unique::Compositing::SubMockChildPreSet.new
1015
+ sub_cascading_composite_array = ::Array::Unique::Compositing::SubMockChildPreSet.new( cascading_composite_array )
1016
+ cascading_composite_array.push( :some_value )
1017
+
1018
+ sub_cascading_composite_array.should == [ :some_other_value ]
1019
+
1020
+ end
1021
+
1022
+ #########################
1023
+ # child_post_set_hook #
1024
+ #########################
1025
+
1026
+ it 'has a hook that is called after setting a value passed by a parent' do
1027
+
1028
+ class ::Array::Unique::Compositing::SubMockChildPostSet < ::Array::Unique::Compositing
1029
+
1030
+ def child_post_set_hook( index, object, is_insert = false )
1031
+ push( :some_other_value )
1032
+ end
1033
+
1034
+ end
1035
+
1036
+ cascading_composite_array = ::Array::Unique::Compositing::SubMockChildPostSet.new
1037
+ sub_cascading_composite_array = ::Array::Unique::Compositing::SubMockChildPostSet.new( cascading_composite_array )
1038
+ cascading_composite_array.push( :some_value )
1039
+
1040
+ cascading_composite_array.should == [ :some_value ]
1041
+ sub_cascading_composite_array.should == [ :some_value, :some_other_value ]
1042
+
1043
+ end
1044
+
1045
+ ###########################
1046
+ # child_pre_delete_hook #
1047
+ ###########################
1048
+
1049
+ it 'has a hook that is called before deleting an index that has been passed by a parent; if return value is false, delete does not occur' do
1050
+
1051
+ class ::Array::Unique::Compositing::SubMockChildPreDelete < ::Array::Unique::Compositing
1052
+
1053
+ def child_pre_delete_hook( index )
1054
+ false
1055
+ end
1056
+
1057
+ end
1058
+
1059
+ cascading_composite_array = ::Array::Unique::Compositing::SubMockChildPreDelete.new
1060
+ sub_cascading_composite_array = ::Array::Unique::Compositing::SubMockChildPreDelete.new( cascading_composite_array )
1061
+ cascading_composite_array.push( :some_value )
1062
+ cascading_composite_array.delete( :some_value )
1063
+
1064
+ cascading_composite_array.should == [ ]
1065
+ sub_cascading_composite_array.should == [ :some_value ]
1066
+
1067
+ end
1068
+
1069
+ ############################
1070
+ # child_post_delete_hook #
1071
+ ############################
1072
+
1073
+ it 'has a hook that is called after deleting an index passed by a parent' do
1074
+
1075
+ class ::Array::Unique::Compositing::SubMockChildPostDelete < ::Array::Unique::Compositing
1076
+
1077
+ def child_post_delete_hook( index, object )
1078
+ delete( :some_other_value )
1079
+ end
1080
+
1081
+ end
1082
+
1083
+ cascading_composite_array = ::Array::Unique::Compositing::SubMockChildPostDelete.new
1084
+ sub_cascading_composite_array = ::Array::Unique::Compositing::SubMockChildPostDelete.new( cascading_composite_array )
1085
+ cascading_composite_array.push( :some_value )
1086
+ sub_cascading_composite_array.push( :some_other_value )
1087
+ cascading_composite_array.delete( :some_value )
1088
+
1089
+ cascading_composite_array.should == [ ]
1090
+ sub_cascading_composite_array.should == [ ]
1091
+
1092
+ end
1093
+
1094
+ end