cascading-configuration-array-sorted-unique 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1008 @@
1
+
2
+ if $__cascading_configuration__spec__development
3
+ require_relative '../../../../../../lib/cascading-configuration-array-sorted-unique.rb'
4
+ else
5
+ require 'cascading-configuration-array-sorted-unique'
6
+ end
7
+
8
+ describe CascadingConfiguration::Array::Sorted::Unique::CompositingArray do
9
+
10
+ before :all do
11
+
12
+ module CascadingConfiguration::Array::Sorted::Unique::CompositingArray::MockA
13
+ # needed for ccv ancestor determination
14
+ def self.some_configuration
15
+ end
16
+ end
17
+ module CascadingConfiguration::Array::Sorted::Unique::CompositingArray::MockB
18
+ end
19
+
20
+ @configuration_instance = CascadingConfiguration::Array::Sorted::Unique::CompositingArray::MockA
21
+ @sub_configuration_instance = CascadingConfiguration::Array::Sorted::Unique::CompositingArray::MockB
22
+
23
+ @configuration_name = :some_configuration
24
+
25
+ CascadingConfiguration::Variable.register_child_for_parent( @sub_configuration_instance,
26
+ @configuration_instance )
27
+
28
+ end
29
+
30
+ ################
31
+ # initialize #
32
+ ################
33
+
34
+ it 'can add initialize with an ancestor, inheriting its values and linking to it as a child' do
35
+
36
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
37
+
38
+ cascading_composite_array.instance_variable_get( :@super_composite_array ).should == nil
39
+ cascading_composite_array.should == []
40
+ cascading_composite_array.push( :A, :B, :C, :D )
41
+
42
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
43
+ sub_cascading_composite_array.instance_variable_get( :@super_composite_array ).should == cascading_composite_array
44
+ sub_cascading_composite_array.should == [ :A, :B, :C, :D ]
45
+
46
+ end
47
+
48
+ ##################################################################################################
49
+ # private #####################################################################################
50
+ ##################################################################################################
51
+
52
+ ##################################################
53
+ # update_corresponding_index_for_parent_change #
54
+ ##################################################
55
+
56
+ it 'can update tracked parent indices for parent insert/delete' do
57
+
58
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
59
+ cascading_composite_array.push( :A, :B )
60
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
61
+
62
+ sub_cascading_composite_array.instance_eval do
63
+ @local_index_for_parent_index[ 0 ].should == 0
64
+ @local_index_for_parent_index[ 1 ].should == 1
65
+ @local_index_for_parent_index[ 2 ].should == nil
66
+ # insert 1 in parent before parent-1
67
+ update_corresponding_index_for_parent_change( 1, 1 )
68
+ @local_index_for_parent_index[ 0 ].should == 0
69
+ # no longer a parent-1 index (has to be set separately)
70
+ @local_index_for_parent_index[ 1 ].should == nil
71
+ # parent-1 is now parent-2
72
+ @local_index_for_parent_index[ 2 ].should == 2
73
+ @parent_and_interpolated_object_count.should == 3
74
+ end
75
+
76
+ end
77
+
78
+ #################################################
79
+ # update_corresponding_index_for_local_change #
80
+ #################################################
81
+
82
+ it 'can update tracked parent indices for local insert/delete' do
83
+
84
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
85
+ cascading_composite_array.push( :A, :B )
86
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
87
+
88
+ sub_cascading_composite_array.instance_eval do
89
+ @local_index_for_parent_index[ 0 ].should == 0
90
+ @local_index_for_parent_index[ 1 ].should == 1
91
+ @local_index_for_parent_index[ 2 ].should == nil
92
+ # insert 1 before parent-1
93
+ update_corresponding_index_for_local_change( 1, 1 )
94
+ @local_index_for_parent_index[ 0 ].should == 0
95
+ # new index for parent-1 is 2
96
+ @local_index_for_parent_index[ 1 ].should == 2
97
+ @local_index_for_parent_index[ 2 ].should == nil
98
+ @parent_and_interpolated_object_count.should == 3
99
+ end
100
+
101
+ end
102
+
103
+ ###########################################
104
+ # update_as_sub_array_for_parent_insert #
105
+ ###########################################
106
+
107
+ it 'can handle updating itself as a sub-array when told an insert has occurred in parent' do
108
+
109
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
110
+ cascading_composite_array.push( :A, :B )
111
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
112
+
113
+ sub_cascading_composite_array.instance_eval do
114
+ @local_index_for_parent_index[ 0 ].should == 0
115
+ @local_index_for_parent_index[ 1 ].should == 1
116
+ @local_index_for_parent_index[ 2 ].should == nil
117
+ # insert 1 before parent-1
118
+ update_as_sub_array_for_parent_insert( 1, :C )
119
+ @local_index_for_parent_index[ 0 ].should == 0
120
+ # new parent index parent-1 inserted for :C
121
+ @local_index_for_parent_index[ 1 ].should == 1
122
+ # new index for parent-1 is parent-2
123
+ @local_index_for_parent_index[ 2 ].should == 2
124
+ @parent_and_interpolated_object_count.should == 3
125
+ end
126
+
127
+ end
128
+
129
+ ########################################
130
+ # update_as_sub_array_for_parent_set #
131
+ ########################################
132
+
133
+ it 'can handle updating itself as a sub-array when told a set has occurred in parent' do
134
+
135
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
136
+ cascading_composite_array.push( :A, :B )
137
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
138
+
139
+ sub_cascading_composite_array.instance_eval do
140
+ @local_index_for_parent_index[ 0 ].should == 0
141
+ @local_index_for_parent_index[ 1 ].should == 1
142
+ @local_index_for_parent_index[ 2 ].should == nil
143
+ # set for parent-1
144
+ update_as_sub_array_for_parent_set( 1, :C )
145
+ @local_index_for_parent_index[ 0 ].should == 0
146
+ @local_index_for_parent_index[ 1 ].should == 0
147
+ @local_index_for_parent_index[ 2 ].should == nil
148
+ @parent_and_interpolated_object_count.should == 2
149
+ end
150
+
151
+ end
152
+
153
+ ###########################################
154
+ # update_as_sub_array_for_parent_delete #
155
+ ###########################################
156
+
157
+ it 'can handle updating itself as a sub-array when told a delete has occurred in parent' do
158
+
159
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
160
+ cascading_composite_array.push( :A, :B )
161
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
162
+
163
+ sub_cascading_composite_array.instance_eval do
164
+ @local_index_for_parent_index[ 0 ].should == 0
165
+ @local_index_for_parent_index[ 1 ].should == 1
166
+ @local_index_for_parent_index[ 2 ].should == nil
167
+ # delete parent-1
168
+ update_as_sub_array_for_parent_delete( 1 )
169
+ @local_index_for_parent_index[ 0 ].should == 0
170
+ @local_index_for_parent_index[ 1 ].should == 1
171
+ @local_index_for_parent_index[ 2 ].should == nil
172
+ @parent_and_interpolated_object_count.should == 1
173
+ end
174
+
175
+ end
176
+
177
+ ##################################################################################################
178
+ # public ######################################################################################
179
+ ##################################################################################################
180
+
181
+ #########
182
+ # []= #
183
+ #########
184
+
185
+ it 'can add elements' do
186
+
187
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
188
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
189
+
190
+ cascading_composite_array[ 0 ] = :A
191
+ cascading_composite_array.should == [ :A ]
192
+ sub_cascading_composite_array.should == [ :A ]
193
+
194
+ cascading_composite_array[ 1 ] = :B
195
+ cascading_composite_array.should == [ :A, :B ]
196
+ sub_cascading_composite_array.should == [ :A, :B ]
197
+
198
+ sub_cascading_composite_array[ 0 ] = :C
199
+ cascading_composite_array.should == [ :A, :B ]
200
+ sub_cascading_composite_array.should == [ :B, :C ]
201
+
202
+ sub_cascading_composite_array[ 0 ] = :B
203
+ cascading_composite_array.should == [ :A, :B ]
204
+ sub_cascading_composite_array.should == [ :B, :C ]
205
+
206
+ sub_cascading_composite_array[ 2 ] = :C
207
+ cascading_composite_array.should == [ :A, :B ]
208
+ sub_cascading_composite_array.should == [ :B, :C ]
209
+
210
+ cascading_composite_array[ 0 ] = :D
211
+ cascading_composite_array.should == [ :B, :D ]
212
+ sub_cascading_composite_array.should == [ :C ]
213
+
214
+ end
215
+
216
+ ############
217
+ # insert #
218
+ ############
219
+
220
+ it 'can insert elements' do
221
+
222
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
223
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
224
+
225
+ cascading_composite_array.insert( 3, :D )
226
+ cascading_composite_array.should == [ nil, :D ]
227
+ sub_cascading_composite_array.should == [ nil, :D ]
228
+
229
+ cascading_composite_array.insert( 1, :B )
230
+ cascading_composite_array.should == [ nil, :B, :D ]
231
+ sub_cascading_composite_array.should == [ nil, :B, :D ]
232
+
233
+ cascading_composite_array.insert( 2, :C )
234
+ cascading_composite_array.should == [ nil, :B, :C, :D ]
235
+ sub_cascading_composite_array.should == [ nil, :B, :C, :D ]
236
+
237
+ sub_cascading_composite_array.insert( 0, :E )
238
+ cascading_composite_array.should == [ nil, :B, :C, :D ]
239
+ sub_cascading_composite_array.should == [ nil, :B, :C, :D, :E ]
240
+
241
+ sub_cascading_composite_array.insert( 4, :F )
242
+ cascading_composite_array.should == [ nil, :B, :C, :D ]
243
+ sub_cascading_composite_array.should == [ nil, :B, :C, :D, :E, :F ]
244
+
245
+ end
246
+
247
+ ##########
248
+ # push #
249
+ # << #
250
+ ##########
251
+
252
+ it 'can add elements' do
253
+
254
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
255
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
256
+
257
+ cascading_composite_array << :A
258
+ cascading_composite_array.should == [ :A ]
259
+ sub_cascading_composite_array.should == [ :A ]
260
+
261
+ cascading_composite_array << :B
262
+ cascading_composite_array.should == [ :A, :B ]
263
+ sub_cascading_composite_array.should == [ :A, :B ]
264
+
265
+ sub_cascading_composite_array << :C
266
+ cascading_composite_array.should == [ :A, :B ]
267
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
268
+
269
+ sub_cascading_composite_array << :B
270
+ cascading_composite_array.should == [ :A, :B ]
271
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
272
+
273
+ end
274
+
275
+ ############
276
+ # concat #
277
+ # + #
278
+ ############
279
+
280
+ it 'can add elements' do
281
+
282
+ # NOTE: this breaks + by causing it to modify the array like +=
283
+ # The alternative was worse.
284
+
285
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
286
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
287
+
288
+ cascading_composite_array.concat( [ :A ] )
289
+ cascading_composite_array.should == [ :A ]
290
+ sub_cascading_composite_array.should == [ :A ]
291
+
292
+ cascading_composite_array += [ :B ]
293
+ cascading_composite_array.should == [ :A, :B ]
294
+ sub_cascading_composite_array.should == [ :A, :B ]
295
+
296
+ sub_cascading_composite_array.concat( [ :C ] )
297
+ cascading_composite_array.should == [ :A, :B ]
298
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
299
+
300
+ sub_cascading_composite_array += [ :B ]
301
+ cascading_composite_array.should == [ :A, :B ]
302
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
303
+
304
+ end
305
+
306
+ ####################
307
+ # delete_objects #
308
+ ####################
309
+
310
+ it 'can delete multiple elements' do
311
+
312
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
313
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
314
+
315
+ cascading_composite_array += [ :A, :B ]
316
+ cascading_composite_array.should == [ :A, :B ]
317
+ sub_cascading_composite_array.should == [ :A, :B ]
318
+
319
+ cascading_composite_array.delete_objects( :A, :B )
320
+ cascading_composite_array.should == [ ]
321
+ sub_cascading_composite_array.should == [ ]
322
+
323
+ sub_cascading_composite_array += [ :B, :C, :D ]
324
+ cascading_composite_array.should == [ ]
325
+ sub_cascading_composite_array.should == [ :B, :C, :D ]
326
+
327
+ sub_cascading_composite_array.delete_objects( :C, :B )
328
+ cascading_composite_array.should == [ ]
329
+ sub_cascading_composite_array.should == [ :D ]
330
+
331
+ end
332
+
333
+ #######
334
+ # - #
335
+ #######
336
+
337
+ it 'can exclude elements' do
338
+
339
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
340
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
341
+
342
+ cascading_composite_array.push( :A )
343
+ cascading_composite_array.should == [ :A ]
344
+ sub_cascading_composite_array.should == [ :A ]
345
+
346
+ cascading_composite_array -= [ :A ]
347
+ cascading_composite_array.should == [ ]
348
+ sub_cascading_composite_array.should == [ ]
349
+
350
+ cascading_composite_array.push( :B )
351
+ cascading_composite_array.should == [ :B ]
352
+ sub_cascading_composite_array.should == [ :B ]
353
+
354
+ sub_cascading_composite_array.push( :C )
355
+ cascading_composite_array.should == [ :B ]
356
+ sub_cascading_composite_array.should == [ :B, :C ]
357
+
358
+ sub_cascading_composite_array -= [ :B ]
359
+ cascading_composite_array.should == [ :B ]
360
+ sub_cascading_composite_array.should == [ :C ]
361
+
362
+ end
363
+
364
+ ############
365
+ # delete #
366
+ ############
367
+
368
+ it 'can delete elements' do
369
+
370
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
371
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
372
+
373
+ cascading_composite_array.push( :A )
374
+ cascading_composite_array.should == [ :A ]
375
+ sub_cascading_composite_array.should == [ :A ]
376
+
377
+ cascading_composite_array.delete( :A )
378
+ cascading_composite_array.should == [ ]
379
+ sub_cascading_composite_array.should == [ ]
380
+
381
+ cascading_composite_array.push( :B )
382
+ cascading_composite_array.should == [ :B ]
383
+ sub_cascading_composite_array.should == [ :B ]
384
+
385
+ sub_cascading_composite_array.push( :C )
386
+ cascading_composite_array.should == [ :B ]
387
+ sub_cascading_composite_array.should == [ :B, :C ]
388
+
389
+ sub_cascading_composite_array.delete( :B )
390
+ cascading_composite_array.should == [ :B ]
391
+ sub_cascading_composite_array.should == [ :C ]
392
+
393
+ end
394
+
395
+ ###############
396
+ # delete_at #
397
+ ###############
398
+
399
+ it 'can delete by indexes' do
400
+
401
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
402
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
403
+
404
+ cascading_composite_array.push( :A )
405
+ cascading_composite_array.should == [ :A ]
406
+ sub_cascading_composite_array.should == [ :A ]
407
+
408
+ cascading_composite_array.delete_at( 0 )
409
+ cascading_composite_array.should == [ ]
410
+ sub_cascading_composite_array.should == [ ]
411
+
412
+ cascading_composite_array.push( :B )
413
+ cascading_composite_array.should == [ :B ]
414
+ sub_cascading_composite_array.should == [ :B ]
415
+
416
+ sub_cascading_composite_array.push( :C )
417
+ cascading_composite_array.should == [ :B ]
418
+ sub_cascading_composite_array.should == [ :B, :C ]
419
+
420
+ sub_cascading_composite_array.delete_at( 0 )
421
+ cascading_composite_array.should == [ :B ]
422
+ sub_cascading_composite_array.should == [ :C ]
423
+
424
+ end
425
+
426
+ #######################
427
+ # delete_at_indexes #
428
+ #######################
429
+
430
+ it 'can delete by indexes' do
431
+
432
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
433
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
434
+
435
+ cascading_composite_array.push( :A, :B, :C )
436
+ cascading_composite_array.should == [ :A, :B, :C ]
437
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
438
+
439
+ cascading_composite_array.delete_at_indexes( 0, 1 )
440
+ cascading_composite_array.should == [ :C ]
441
+ sub_cascading_composite_array.should == [ :C ]
442
+
443
+ sub_cascading_composite_array.push( :C, :B )
444
+ cascading_composite_array.should == [ :C ]
445
+ sub_cascading_composite_array.should == [ :B, :C ]
446
+
447
+ sub_cascading_composite_array.delete_at_indexes( 0, 1, 2 )
448
+ cascading_composite_array.should == [ :C ]
449
+ sub_cascading_composite_array.should == [ ]
450
+
451
+ end
452
+
453
+ ###############
454
+ # delete_if #
455
+ ###############
456
+
457
+ it 'can delete by block' do
458
+
459
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
460
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
461
+
462
+ cascading_composite_array.push( :A, :B, :C )
463
+ cascading_composite_array.should == [ :A, :B, :C ]
464
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
465
+ cascading_composite_array.delete_if do |object|
466
+ object != :C
467
+ end
468
+ cascading_composite_array.should == [ :C ]
469
+ sub_cascading_composite_array.should == [ :C ]
470
+
471
+ sub_cascading_composite_array.push( :C, :B )
472
+ cascading_composite_array.should == [ :C ]
473
+ sub_cascading_composite_array.should == [ :B, :C ]
474
+ sub_cascading_composite_array.delete_if do |object|
475
+ object != nil
476
+ end
477
+ sub_cascading_composite_array.should == [ ]
478
+ cascading_composite_array.should == [ :C ]
479
+
480
+ cascading_composite_array.delete_if.is_a?( Enumerator ).should == true
481
+
482
+ end
483
+
484
+ #############
485
+ # keep_if #
486
+ #############
487
+
488
+ it 'can keep by block' do
489
+
490
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
491
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
492
+
493
+ cascading_composite_array.push( :A, :B, :C )
494
+ cascading_composite_array.should == [ :A, :B, :C ]
495
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
496
+ cascading_composite_array.keep_if do |object|
497
+ object == :C
498
+ end
499
+ cascading_composite_array.should == [ :C ]
500
+ sub_cascading_composite_array.should == [ :C ]
501
+
502
+ sub_cascading_composite_array.push( :C, :B )
503
+ cascading_composite_array.should == [ :C ]
504
+ sub_cascading_composite_array.should == [ :B, :C ]
505
+ sub_cascading_composite_array.keep_if do |object|
506
+ object == nil
507
+ end
508
+ cascading_composite_array.should == [ :C ]
509
+ sub_cascading_composite_array.should == [ ]
510
+
511
+ end
512
+
513
+ ##############
514
+ # compact! #
515
+ ##############
516
+
517
+ it 'can compact' do
518
+
519
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
520
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
521
+
522
+ cascading_composite_array.push( :A, nil, :B, nil, :C, nil )
523
+ cascading_composite_array.should == [ nil, :A, :B, :C ]
524
+ sub_cascading_composite_array.should == [ nil, :A, :B, :C ]
525
+ cascading_composite_array.compact!
526
+ cascading_composite_array.should == [ :A, :B, :C ]
527
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
528
+
529
+ sub_cascading_composite_array.push( nil, :D )
530
+ cascading_composite_array.should == [ :A, :B, :C ]
531
+ sub_cascading_composite_array.should == [ nil, :A, :B, :C, :D ]
532
+ sub_cascading_composite_array.compact!
533
+ cascading_composite_array.should == [ :A, :B, :C ]
534
+ sub_cascading_composite_array.should == [ :A, :B, :C, :D ]
535
+
536
+ end
537
+
538
+ ##############
539
+ # flatten! #
540
+ ##############
541
+
542
+ it 'can flatten' do
543
+
544
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
545
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
546
+
547
+ cascading_composite_array.push( :A, [ :F_A, :F_B ], :B, [ :F_C ], :C, [ :F_D ], [ :F_E ] )
548
+ cascading_composite_array.should == [ :A, [ :F_A, :F_B ], :B, [ :F_C ], :C, [ :F_D ], [ :F_E ] ]
549
+ sub_cascading_composite_array.should == [ :A, [ :F_A, :F_B ], :B, [ :F_C ], :C, [ :F_D ], [ :F_E ] ]
550
+ cascading_composite_array.flatten!
551
+ cascading_composite_array.should == [ :A, :B, :C, :F_A, :F_B, :F_C, :F_D, :F_E ]
552
+ sub_cascading_composite_array.should == [ :A, :B, :C, :F_A, :F_B, :F_C, :F_D, :F_E ]
553
+
554
+ sub_cascading_composite_array.push( [ :F_F, :F_G ], :D, [ :F_H ] )
555
+ cascading_composite_array.should == [ :A, :B, :C, :F_A, :F_B, :F_C, :F_D, :F_E ]
556
+ sub_cascading_composite_array.should == [ :A, :B, :C, :D, :F_A, :F_B, :F_C, :F_D, :F_E, [ :F_F, :F_G ], [ :F_H ] ]
557
+ sub_cascading_composite_array.flatten!
558
+ cascading_composite_array.should == [ :A, :B, :C, :F_A, :F_B, :F_C, :F_D, :F_E ]
559
+ sub_cascading_composite_array.should == [ :A, :B, :C, :D, :F_A, :F_B, :F_C, :F_D, :F_E, :F_F, :F_G, :F_H ]
560
+
561
+ end
562
+
563
+ #############
564
+ # reject! #
565
+ #############
566
+
567
+ it 'can reject' do
568
+
569
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
570
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
571
+
572
+ cascading_composite_array.push( :A, :B, :C )
573
+ cascading_composite_array.should == [ :A, :B, :C ]
574
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
575
+ cascading_composite_array.reject! do |object|
576
+ object != :C
577
+ end
578
+ cascading_composite_array.should == [ :C ]
579
+ sub_cascading_composite_array.should == [ :C ]
580
+
581
+ sub_cascading_composite_array.push( :C, :B )
582
+ cascading_composite_array.should == [ :C ]
583
+ sub_cascading_composite_array.should == [ :B, :C ]
584
+ sub_cascading_composite_array.reject! do |object|
585
+ object != nil
586
+ end
587
+ sub_cascading_composite_array.should == [ ]
588
+ cascading_composite_array.should == [ :C ]
589
+
590
+ cascading_composite_array.reject!.is_a?( Enumerator ).should == true
591
+
592
+ end
593
+
594
+ #############
595
+ # replace #
596
+ #############
597
+
598
+ it 'can replace self' do
599
+
600
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
601
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
602
+
603
+ cascading_composite_array.push( :A, :B, :C )
604
+ cascading_composite_array.should == [ :A, :B, :C ]
605
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
606
+ cascading_composite_array.replace( [ :D, :E, :F ] )
607
+ cascading_composite_array.should == [ :D, :E, :F ]
608
+ sub_cascading_composite_array.should == [ :D, :E, :F ]
609
+
610
+ cascading_composite_array.should == [ :D, :E, :F ]
611
+ sub_cascading_composite_array.should == [ :D, :E, :F ]
612
+ sub_cascading_composite_array.replace( [ :G, :H, :I ] )
613
+ cascading_composite_array.should == [ :D, :E, :F ]
614
+ sub_cascading_composite_array.should == [ :G, :H, :I ]
615
+
616
+ end
617
+
618
+ ##############
619
+ # reverse! #
620
+ ##############
621
+
622
+ it 'can reverse self' do
623
+
624
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
625
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
626
+
627
+ cascading_composite_array.push( :A, :B, :C )
628
+ cascading_composite_array.should == [ :A, :B, :C ]
629
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
630
+ cascading_composite_array.reverse!
631
+ cascading_composite_array.should == [ :C, :B, :A ]
632
+ sub_cascading_composite_array.should == [ :C, :B, :A ]
633
+
634
+ cascading_composite_array.should == [ :C, :B, :A ]
635
+ sub_cascading_composite_array.should == [ :C, :B, :A ]
636
+ sub_cascading_composite_array.reverse!
637
+ cascading_composite_array.should == [ :C, :B, :A ]
638
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
639
+
640
+ end
641
+
642
+ #############
643
+ # rotate! #
644
+ #############
645
+
646
+ it 'can rotate self' do
647
+
648
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
649
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
650
+
651
+ cascading_composite_array.push( :A, :B, :C )
652
+ cascading_composite_array.should == [ :A, :B, :C ]
653
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
654
+
655
+ cascading_composite_array.rotate!
656
+ cascading_composite_array.should == [ :A, :B, :C ]
657
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
658
+
659
+ cascading_composite_array.rotate!( -1 )
660
+ cascading_composite_array.should == [ :A, :B, :C ]
661
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
662
+
663
+ sub_cascading_composite_array.rotate!( 2 )
664
+ cascading_composite_array.should == [ :A, :B, :C ]
665
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
666
+
667
+ end
668
+
669
+ #############
670
+ # select! #
671
+ #############
672
+
673
+ it 'can keep by select' do
674
+
675
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
676
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
677
+
678
+ cascading_composite_array.push( :A, :B, :C )
679
+ cascading_composite_array.should == [ :A, :B, :C ]
680
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
681
+ cascading_composite_array.select! do |object|
682
+ object == :C
683
+ end
684
+ cascading_composite_array.should == [ :C ]
685
+ sub_cascading_composite_array.should == [ :C ]
686
+
687
+ sub_cascading_composite_array.push( :C, :B )
688
+ cascading_composite_array.should == [ :C ]
689
+ sub_cascading_composite_array.should == [ :B, :C ]
690
+ sub_cascading_composite_array.select! do |object|
691
+ object == nil
692
+ end
693
+ cascading_composite_array.should == [ :C ]
694
+ sub_cascading_composite_array.should == [ ]
695
+
696
+ cascading_composite_array.select!.is_a?( Enumerator ).should == true
697
+
698
+ end
699
+
700
+ ##############
701
+ # shuffle! #
702
+ ##############
703
+
704
+ it 'can shuffle self' do
705
+
706
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
707
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
708
+
709
+ cascading_composite_array.push( :A, :B, :C )
710
+ cascading_composite_array.should == [ :A, :B, :C ]
711
+ sub_cascading_composite_array.should == cascading_composite_array
712
+
713
+ first_shuffle_version = cascading_composite_array.dup
714
+ cascading_composite_array.shuffle!
715
+ cascading_composite_array.should == first_shuffle_version
716
+ sub_cascading_composite_array.should == cascading_composite_array
717
+
718
+ first_shuffle_version = sub_cascading_composite_array.dup
719
+ sub_cascading_composite_array.shuffle!
720
+ sub_cascading_composite_array.should == first_shuffle_version
721
+ sub_cascading_composite_array.should == cascading_composite_array
722
+
723
+ end
724
+
725
+ ##############
726
+ # collect! #
727
+ # map! #
728
+ ##############
729
+
730
+ it 'can replace by collect/map' do
731
+
732
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
733
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
734
+
735
+ cascading_composite_array.push( :A, :B, :C )
736
+ cascading_composite_array.should == [ :A, :B, :C ]
737
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
738
+ cascading_composite_array.collect! do |object|
739
+ :C
740
+ end
741
+ cascading_composite_array.should == [ :C, ]
742
+ sub_cascading_composite_array.should == [ :C ]
743
+
744
+ sub_cascading_composite_array.collect! do |object|
745
+ :A
746
+ end
747
+ cascading_composite_array.should == [ :C ]
748
+ sub_cascading_composite_array.should == [ :A ]
749
+
750
+ cascading_composite_array.collect!.is_a?( Enumerator ).should == true
751
+
752
+ end
753
+
754
+ ###########
755
+ # sort! #
756
+ ###########
757
+
758
+ it 'can replace by collect/map' do
759
+
760
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
761
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
762
+
763
+ cascading_composite_array.push( :A, :B, :C )
764
+ cascading_composite_array.should == [ :A, :B, :C ]
765
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
766
+ cascading_composite_array.sort! do |a, b|
767
+ if a < b
768
+ 1
769
+ elsif a > b
770
+ -1
771
+ elsif a == b
772
+ 0
773
+ end
774
+ end
775
+ cascading_composite_array.should == [ :A, :B, :C ]
776
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
777
+
778
+ sub_cascading_composite_array.sort! do |a, b|
779
+ if a < b
780
+ -1
781
+ elsif a > b
782
+ 1
783
+ elsif a == b
784
+ 0
785
+ end
786
+ end
787
+ cascading_composite_array.should == [ :A, :B, :C ]
788
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
789
+
790
+ cascading_composite_array.sort!
791
+ cascading_composite_array.should == [ :A, :B, :C ]
792
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
793
+
794
+ end
795
+
796
+ ##############
797
+ # sort_by! #
798
+ ##############
799
+
800
+ it 'can replace by collect/map' do
801
+
802
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
803
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
804
+
805
+ cascading_composite_array.push( :A, :B, :C )
806
+ cascading_composite_array.should == [ :A, :B, :C ]
807
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
808
+ cascading_composite_array.sort_by! do |object|
809
+ case object
810
+ when :A
811
+ :B
812
+ when :B
813
+ :A
814
+ when :C
815
+ :C
816
+ end
817
+ end
818
+ cascading_composite_array.should == [ :A, :B, :C ]
819
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
820
+
821
+ sub_cascading_composite_array.sort_by! do |object|
822
+ case object
823
+ when :A
824
+ :C
825
+ when :B
826
+ :B
827
+ when :C
828
+ :A
829
+ end
830
+ end
831
+ cascading_composite_array.should == [ :A, :B, :C ]
832
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
833
+
834
+ cascading_composite_array.sort_by!.is_a?( Enumerator ).should == true
835
+
836
+ end
837
+
838
+ ###########
839
+ # uniq! #
840
+ ###########
841
+
842
+ it 'can remove non-unique elements' do
843
+
844
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
845
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
846
+
847
+ cascading_composite_array.push( :A, :B, :C, :C, :C, :B, :A )
848
+ cascading_composite_array.should == [ :A, :B, :C ]
849
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
850
+ cascading_composite_array.uniq!
851
+ cascading_composite_array.should == [ :A, :B, :C ]
852
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
853
+
854
+ sub_cascading_composite_array.push( :C, :B )
855
+ cascading_composite_array.should == [ :A, :B, :C ]
856
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
857
+ sub_cascading_composite_array.uniq!
858
+ cascading_composite_array.should == [ :A, :B, :C ]
859
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
860
+
861
+ end
862
+
863
+ #############
864
+ # unshift #
865
+ #############
866
+
867
+ it 'can unshift onto the first element' do
868
+
869
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
870
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
871
+
872
+ cascading_composite_array += :A
873
+ cascading_composite_array.should == [ :A ]
874
+ sub_cascading_composite_array.should == [ :A ]
875
+
876
+ cascading_composite_array.unshift( :B )
877
+ cascading_composite_array.should == [ :A, :B ]
878
+ sub_cascading_composite_array.should == [ :A, :B ]
879
+
880
+ sub_cascading_composite_array.unshift( :C )
881
+ cascading_composite_array.should == [ :A, :B ]
882
+ sub_cascading_composite_array.should == [ :A, :B, :C ]
883
+
884
+ end
885
+
886
+ #########
887
+ # pop #
888
+ #########
889
+
890
+ it 'can pop the final element' do
891
+
892
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
893
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
894
+
895
+ cascading_composite_array += :A
896
+ cascading_composite_array.should == [ :A ]
897
+ sub_cascading_composite_array.should == [ :A ]
898
+
899
+ cascading_composite_array.pop.should == :A
900
+ cascading_composite_array.should == [ ]
901
+ sub_cascading_composite_array.should == [ ]
902
+
903
+ cascading_composite_array += :B
904
+ cascading_composite_array.should == [ :B ]
905
+ sub_cascading_composite_array.should == [ :B ]
906
+
907
+ sub_cascading_composite_array += :C
908
+ cascading_composite_array.should == [ :B ]
909
+ sub_cascading_composite_array.should == [ :B, :C ]
910
+ sub_cascading_composite_array.pop.should == :C
911
+ cascading_composite_array.should == [ :B ]
912
+ sub_cascading_composite_array.should == [ :B ]
913
+
914
+ end
915
+
916
+ ###########
917
+ # shift #
918
+ ###########
919
+
920
+ it 'can shift the first element' do
921
+
922
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
923
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
924
+
925
+ cascading_composite_array += :A
926
+ cascading_composite_array.should == [ :A ]
927
+ sub_cascading_composite_array.should == [ :A ]
928
+
929
+ cascading_composite_array.shift.should == :A
930
+ cascading_composite_array.should == [ ]
931
+ sub_cascading_composite_array.should == [ ]
932
+
933
+ cascading_composite_array += :B
934
+ cascading_composite_array.should == [ :B ]
935
+ sub_cascading_composite_array.should == [ :B ]
936
+
937
+ sub_cascading_composite_array += :C
938
+ cascading_composite_array.should == [ :B ]
939
+ sub_cascading_composite_array.should == [ :B, :C ]
940
+ sub_cascading_composite_array.shift.should == :B
941
+ cascading_composite_array.should == [ :B ]
942
+ sub_cascading_composite_array.should == [ :C ]
943
+
944
+ end
945
+
946
+ ############
947
+ # slice! #
948
+ ############
949
+
950
+ it 'can slice elements' do
951
+
952
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
953
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
954
+
955
+ cascading_composite_array += :A
956
+ cascading_composite_array.should == [ :A ]
957
+ sub_cascading_composite_array.should == [ :A ]
958
+
959
+ cascading_composite_array.slice!( 0, 1 ).should == [ :A ]
960
+ cascading_composite_array.should == [ ]
961
+ sub_cascading_composite_array.should == [ ]
962
+
963
+ cascading_composite_array += :B
964
+ cascading_composite_array.should == [ :B ]
965
+ sub_cascading_composite_array.should == [ :B ]
966
+
967
+ sub_cascading_composite_array += :C
968
+ cascading_composite_array.should == [ :B ]
969
+ sub_cascading_composite_array.should == [ :B, :C ]
970
+
971
+ sub_cascading_composite_array.slice!( 0, 1 ).should == [ :B ]
972
+ cascading_composite_array.should == [ :B ]
973
+ sub_cascading_composite_array.should == [ :C ]
974
+
975
+ end
976
+
977
+ ###########
978
+ # clear #
979
+ ###########
980
+
981
+ it 'can clear, causing present elements to be excluded' do
982
+
983
+ cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @configuration_instance, @configuration_name )
984
+ sub_cascading_composite_array = CascadingConfiguration::Array::Sorted::Unique::CompositingArray.new( @sub_configuration_instance, @configuration_name )
985
+
986
+ cascading_composite_array += :A
987
+ cascading_composite_array.should == [ :A ]
988
+ sub_cascading_composite_array.should == [ :A ]
989
+
990
+ cascading_composite_array.clear
991
+ cascading_composite_array.should == [ ]
992
+ sub_cascading_composite_array.should == [ ]
993
+
994
+ cascading_composite_array += :B
995
+ cascading_composite_array.should == [ :B ]
996
+ sub_cascading_composite_array.should == [ :B ]
997
+
998
+ sub_cascading_composite_array += :C
999
+ cascading_composite_array.should == [ :B ]
1000
+ sub_cascading_composite_array.should == [ :B, :C ]
1001
+
1002
+ sub_cascading_composite_array.clear
1003
+ cascading_composite_array.should == [ :B ]
1004
+ sub_cascading_composite_array.should == [ ]
1005
+
1006
+ end
1007
+
1008
+ end