cascading-configuration-array 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,44 +0,0 @@
1
-
2
- module ::CascadingConfiguration::Array::ModuleSupportMethods
3
-
4
- #####################
5
- # composite_array #
6
- #####################
7
-
8
- def composite_array( configuration_instance, configuration_name )
9
-
10
- composite_array = nil
11
-
12
- if ::CascadingConfiguration::Variable.has_configuration_variable?( configuration_instance,
13
- configuration_name )
14
- composite_array = ::CascadingConfiguration::Variable.
15
- get_configuration_variable( configuration_instance, configuration_name )
16
- else
17
- composite_array = ::CascadingConfiguration::Array::CompositingArray.
18
- new( configuration_instance, configuration_name )
19
- end
20
-
21
- return composite_array
22
-
23
- end
24
-
25
- #########################
26
- # set_composite_array #
27
- #########################
28
-
29
- def set_composite_array( configuration_instance, configuration_name, array )
30
-
31
- composite_array = composite_array( configuration_instance, configuration_name )
32
-
33
- # we want the array to supplant existing config
34
- # clear the array (excludes everything explicitly)
35
- composite_array.clear
36
-
37
- # push array elements (removes anything excluded from exclude)
38
- composite_array.push( *array )
39
-
40
- return composite_array
41
-
42
- end
43
-
44
- end
@@ -1,1020 +0,0 @@
1
-
2
- if $__cascading_configuration__spec__development
3
- require_relative '../../../../lib/cascading-configuration-array.rb'
4
- else
5
- require 'cascading-configuration-array'
6
- end
7
-
8
- describe CascadingConfiguration::Array::CompositingArray do
9
-
10
- before :all do
11
-
12
- module ::CascadingConfiguration::Array::CompositingArray::MockA
13
- # needed for ccv ancestor determination
14
- def self.some_configuration
15
- end
16
- end
17
- module ::CascadingConfiguration::Array::CompositingArray::MockB
18
- end
19
-
20
- @configuration_instance = CascadingConfiguration::Array::CompositingArray::MockA
21
- @sub_configuration_instance = CascadingConfiguration::Array::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::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::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::CompositingArray.new( @configuration_instance, @configuration_name )
59
- cascading_composite_array.push( :A, :B )
60
- sub_cascading_composite_array = CascadingConfiguration::Array::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::CompositingArray.new( @configuration_instance, @configuration_name )
85
- cascading_composite_array.push( :A, :B )
86
- sub_cascading_composite_array = CascadingConfiguration::Array::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::CompositingArray.new( @configuration_instance, @configuration_name )
110
- cascading_composite_array.push( :A, :B )
111
- sub_cascading_composite_array = CascadingConfiguration::Array::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::CompositingArray.new( @configuration_instance, @configuration_name )
136
- cascading_composite_array.push( :A, :B )
137
- sub_cascading_composite_array = CascadingConfiguration::Array::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 == 1
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::CompositingArray.new( @configuration_instance, @configuration_name )
160
- cascading_composite_array.push( :A, :B )
161
- sub_cascading_composite_array = CascadingConfiguration::Array::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::CompositingArray.new( @configuration_instance, @configuration_name )
188
- sub_cascading_composite_array = CascadingConfiguration::Array::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 == [ :C, :B ]
201
-
202
- sub_cascading_composite_array[ 0 ] = :B
203
- cascading_composite_array.should == [ :A, :B ]
204
- sub_cascading_composite_array.should == [ :B, :B ]
205
-
206
- sub_cascading_composite_array[ 2 ] = :C
207
- cascading_composite_array.should == [ :A, :B ]
208
- sub_cascading_composite_array.should == [ :B, :B, :C ]
209
-
210
- cascading_composite_array[ 0 ] = :D
211
- cascading_composite_array.should == [ :D, :B ]
212
- sub_cascading_composite_array.should == [ :B, :B, :C ]
213
-
214
- end
215
-
216
- ############
217
- # insert #
218
- ############
219
-
220
- it 'can insert elements' do
221
-
222
- cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @configuration_instance, @configuration_name )
223
- sub_cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @sub_configuration_instance, @configuration_name )
224
-
225
- cascading_composite_array.insert( 3, :D )
226
- cascading_composite_array.should == [ nil, nil, nil, :D ]
227
- sub_cascading_composite_array.should == [ nil, nil, nil, :D ]
228
-
229
- cascading_composite_array.insert( 1, :B )
230
- cascading_composite_array.should == [ nil, :B, nil, nil, :D ]
231
- sub_cascading_composite_array.should == [ nil, :B, nil, nil, :D ]
232
-
233
- cascading_composite_array.insert( 2, :C )
234
- cascading_composite_array.should == [ nil, :B, :C, nil, nil, :D ]
235
- sub_cascading_composite_array.should == [ nil, :B, :C, nil, nil, :D ]
236
-
237
- sub_cascading_composite_array.insert( 0, :E )
238
- cascading_composite_array.should == [ nil, :B, :C, nil, nil, :D ]
239
- sub_cascading_composite_array.should == [ :E, nil, :B, :C, nil, nil, :D ]
240
-
241
- sub_cascading_composite_array.insert( 4, :F )
242
- cascading_composite_array.should == [ nil, :B, :C, nil, nil, :D ]
243
- sub_cascading_composite_array.should == [ :E, nil, :B, :C, :F, nil, nil, :D ]
244
-
245
- end
246
-
247
- ##########
248
- # push #
249
- # << #
250
- ##########
251
-
252
- it 'can add elements' do
253
-
254
- cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @configuration_instance, @configuration_name )
255
- sub_cascading_composite_array = CascadingConfiguration::Array::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, :B ]
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::CompositingArray.new( @configuration_instance, @configuration_name )
286
- sub_cascading_composite_array = CascadingConfiguration::Array::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, :B ]
303
-
304
- end
305
-
306
- ####################
307
- # delete_objects #
308
- ####################
309
-
310
- it 'can delete multiple elements' do
311
-
312
- cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @configuration_instance, @configuration_name )
313
- sub_cascading_composite_array = CascadingConfiguration::Array::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::CompositingArray.new( @configuration_instance, @configuration_name )
340
- sub_cascading_composite_array = CascadingConfiguration::Array::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::CompositingArray.new( @configuration_instance, @configuration_name )
371
- sub_cascading_composite_array = CascadingConfiguration::Array::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::CompositingArray.new( @configuration_instance, @configuration_name )
402
- sub_cascading_composite_array = CascadingConfiguration::Array::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::CompositingArray.new( @configuration_instance, @configuration_name )
433
- sub_cascading_composite_array = CascadingConfiguration::Array::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 == [ :C, :C, :B ]
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::CompositingArray.new( @configuration_instance, @configuration_name )
460
- sub_cascading_composite_array = CascadingConfiguration::Array::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 == [ :C, :C, :B ]
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::CompositingArray.new( @configuration_instance, @configuration_name )
491
- sub_cascading_composite_array = CascadingConfiguration::Array::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 == [ :C, :C, :B ]
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::CompositingArray.new( @configuration_instance, @configuration_name )
520
- sub_cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @sub_configuration_instance, @configuration_name )
521
-
522
- cascading_composite_array.push( :A, nil, :B, nil, :C, nil )
523
- cascading_composite_array.should == [ :A, nil, :B, nil, :C, nil ]
524
- sub_cascading_composite_array.should == [ :A, nil, :B, nil, :C, nil ]
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, nil, :D )
530
- cascading_composite_array.should == [ :A, :B, :C ]
531
- sub_cascading_composite_array.should == [ :A, :B, :C, nil, nil, :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::CompositingArray.new( @configuration_instance, @configuration_name )
545
- sub_cascading_composite_array = CascadingConfiguration::Array::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, :F_A, :F_B, :B, :F_C, :C, :F_D, :F_E ]
552
- sub_cascading_composite_array.should == [ :A, :F_A, :F_B, :B, :F_C, :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, :F_A, :F_B, :B, :F_C, :C, :F_D, :F_E ]
556
- 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 ] ]
557
- sub_cascading_composite_array.flatten!
558
- cascading_composite_array.should == [ :A, :F_A, :F_B, :B, :F_C, :C, :F_D, :F_E ]
559
- 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 ]
560
-
561
- end
562
-
563
- #############
564
- # reject! #
565
- #############
566
-
567
- it 'can reject' do
568
-
569
- cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @configuration_instance, @configuration_name )
570
- sub_cascading_composite_array = CascadingConfiguration::Array::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 == [ :C, :C, :B ]
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::CompositingArray.new( @configuration_instance, @configuration_name )
601
- sub_cascading_composite_array = CascadingConfiguration::Array::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::CompositingArray.new( @configuration_instance, @configuration_name )
625
- sub_cascading_composite_array = CascadingConfiguration::Array::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::CompositingArray.new( @configuration_instance, @configuration_name )
649
- sub_cascading_composite_array = CascadingConfiguration::Array::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 == [ :B, :C, :A ]
657
- sub_cascading_composite_array.should == [ :B, :C, :A ]
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 == [ :C, :A, :B ]
666
-
667
- end
668
-
669
- #############
670
- # select! #
671
- #############
672
-
673
- it 'can keep by select' do
674
-
675
- cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @configuration_instance, @configuration_name )
676
- sub_cascading_composite_array = CascadingConfiguration::Array::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 == [ :C, :C, :B ]
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::CompositingArray.new( @configuration_instance, @configuration_name )
707
- sub_cascading_composite_array = CascadingConfiguration::Array::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
- prior_version = cascading_composite_array.dup
714
- attempts = [ ]
715
- 50.times do
716
- cascading_composite_array.shuffle!
717
- attempts.push( cascading_composite_array == prior_version )
718
- prior_version = cascading_composite_array.dup
719
- end
720
- attempts_correct = attempts.select { |member| member == false }.count
721
- ( attempts_correct >= 10 ).should == true
722
- sub_cascading_composite_array.should == cascading_composite_array
723
- first_shuffle_version = cascading_composite_array
724
-
725
- cascading_composite_array.should == first_shuffle_version
726
- attempts = [ ]
727
- 50.times do
728
- sub_cascading_composite_array.shuffle!
729
- attempts.push( sub_cascading_composite_array == cascading_composite_array )
730
- prior_version = cascading_composite_array.dup
731
- end
732
- attempts_correct = attempts.select { |member| member == false }.count
733
- ( attempts_correct >= 10 ).should == true
734
-
735
- end
736
-
737
- ##############
738
- # collect! #
739
- # map! #
740
- ##############
741
-
742
- it 'can replace by collect/map' do
743
-
744
- cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @configuration_instance, @configuration_name )
745
- sub_cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @sub_configuration_instance, @configuration_name )
746
-
747
- cascading_composite_array.push( :A, :B, :C )
748
- cascading_composite_array.should == [ :A, :B, :C ]
749
- sub_cascading_composite_array.should == [ :A, :B, :C ]
750
- cascading_composite_array.collect! do |object|
751
- :C
752
- end
753
- cascading_composite_array.should == [ :C, :C, :C ]
754
- sub_cascading_composite_array.should == [ :C, :C, :C ]
755
-
756
- sub_cascading_composite_array.collect! do |object|
757
- :A
758
- end
759
- cascading_composite_array.should == [ :C, :C, :C ]
760
- sub_cascading_composite_array.should == [ :A, :A, :A ]
761
-
762
- cascading_composite_array.collect!.is_a?( Enumerator ).should == true
763
-
764
- end
765
-
766
- ###########
767
- # sort! #
768
- ###########
769
-
770
- it 'can replace by collect/map' do
771
-
772
- cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @configuration_instance, @configuration_name )
773
- sub_cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @sub_configuration_instance, @configuration_name )
774
-
775
- cascading_composite_array.push( :A, :B, :C )
776
- cascading_composite_array.should == [ :A, :B, :C ]
777
- sub_cascading_composite_array.should == [ :A, :B, :C ]
778
- 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 == [ :C, :B, :A ]
788
- sub_cascading_composite_array.should == [ :C, :B, :A ]
789
-
790
- sub_cascading_composite_array.sort! do |a, b|
791
- if a < b
792
- -1
793
- elsif a > b
794
- 1
795
- elsif a == b
796
- 0
797
- end
798
- end
799
- cascading_composite_array.should == [ :C, :B, :A ]
800
- sub_cascading_composite_array.should == [ :A, :B, :C ]
801
-
802
- cascading_composite_array.sort!
803
- cascading_composite_array.should == [ :A, :B, :C ]
804
- sub_cascading_composite_array.should == [ :A, :B, :C ]
805
-
806
- end
807
-
808
- ##############
809
- # sort_by! #
810
- ##############
811
-
812
- it 'can replace by collect/map' do
813
-
814
- cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @configuration_instance, @configuration_name )
815
- sub_cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @sub_configuration_instance, @configuration_name )
816
-
817
- cascading_composite_array.push( :A, :B, :C )
818
- cascading_composite_array.should == [ :A, :B, :C ]
819
- sub_cascading_composite_array.should == [ :A, :B, :C ]
820
- cascading_composite_array.sort_by! do |object|
821
- case object
822
- when :A
823
- :B
824
- when :B
825
- :A
826
- when :C
827
- :C
828
- end
829
- end
830
- cascading_composite_array.should == [ :B, :A, :C ]
831
- sub_cascading_composite_array.should == [ :B, :A, :C ]
832
-
833
- sub_cascading_composite_array.sort_by! do |object|
834
- case object
835
- when :A
836
- :C
837
- when :B
838
- :B
839
- when :C
840
- :A
841
- end
842
- end
843
- cascading_composite_array.should == [ :B, :A, :C ]
844
- sub_cascading_composite_array.should == [ :C, :B, :A ]
845
-
846
- cascading_composite_array.sort_by!.is_a?( Enumerator ).should == true
847
-
848
- end
849
-
850
- ###########
851
- # uniq! #
852
- ###########
853
-
854
- it 'can remove non-unique elements' do
855
-
856
- cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @configuration_instance, @configuration_name )
857
- sub_cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @sub_configuration_instance, @configuration_name )
858
-
859
- cascading_composite_array.push( :A, :B, :C, :C, :C, :B, :A )
860
- cascading_composite_array.should == [ :A, :B, :C, :C, :C, :B, :A ]
861
- sub_cascading_composite_array.should == [ :A, :B, :C, :C, :C, :B, :A ]
862
- cascading_composite_array.uniq!
863
- cascading_composite_array.should == [ :A, :B, :C ]
864
- sub_cascading_composite_array.should == [ :A, :B, :C ]
865
-
866
- sub_cascading_composite_array.push( :C, :B )
867
- cascading_composite_array.should == [ :A, :B, :C ]
868
- sub_cascading_composite_array.should == [ :A, :B, :C, :C, :B ]
869
- sub_cascading_composite_array.uniq!
870
- cascading_composite_array.should == [ :A, :B, :C ]
871
- sub_cascading_composite_array.should == [ :A, :B, :C ]
872
-
873
- end
874
-
875
- #############
876
- # unshift #
877
- #############
878
-
879
- it 'can unshift onto the first element' do
880
-
881
- cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @configuration_instance, @configuration_name )
882
- sub_cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @sub_configuration_instance, @configuration_name )
883
-
884
- cascading_composite_array += :A
885
- cascading_composite_array.should == [ :A ]
886
- sub_cascading_composite_array.should == [ :A ]
887
-
888
- cascading_composite_array.unshift( :B )
889
- cascading_composite_array.should == [ :B, :A ]
890
- sub_cascading_composite_array.should == [ :B, :A ]
891
-
892
- sub_cascading_composite_array.unshift( :C )
893
- cascading_composite_array.should == [ :B, :A ]
894
- sub_cascading_composite_array.should == [ :C, :B, :A ]
895
-
896
- end
897
-
898
- #########
899
- # pop #
900
- #########
901
-
902
- it 'can pop the final element' do
903
-
904
- cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @configuration_instance, @configuration_name )
905
- sub_cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @sub_configuration_instance, @configuration_name )
906
-
907
- cascading_composite_array += :A
908
- cascading_composite_array.should == [ :A ]
909
- sub_cascading_composite_array.should == [ :A ]
910
-
911
- cascading_composite_array.pop.should == :A
912
- cascading_composite_array.should == [ ]
913
- sub_cascading_composite_array.should == [ ]
914
-
915
- cascading_composite_array += :B
916
- cascading_composite_array.should == [ :B ]
917
- sub_cascading_composite_array.should == [ :B ]
918
-
919
- sub_cascading_composite_array += :C
920
- cascading_composite_array.should == [ :B ]
921
- sub_cascading_composite_array.should == [ :B, :C ]
922
- sub_cascading_composite_array.pop.should == :C
923
- cascading_composite_array.should == [ :B ]
924
- sub_cascading_composite_array.should == [ :B ]
925
-
926
- end
927
-
928
- ###########
929
- # shift #
930
- ###########
931
-
932
- it 'can shift the first element' do
933
-
934
- cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @configuration_instance, @configuration_name )
935
- sub_cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @sub_configuration_instance, @configuration_name )
936
-
937
- cascading_composite_array += :A
938
- cascading_composite_array.should == [ :A ]
939
- sub_cascading_composite_array.should == [ :A ]
940
-
941
- cascading_composite_array.shift.should == :A
942
- cascading_composite_array.should == [ ]
943
- sub_cascading_composite_array.should == [ ]
944
-
945
- cascading_composite_array += :B
946
- cascading_composite_array.should == [ :B ]
947
- sub_cascading_composite_array.should == [ :B ]
948
-
949
- sub_cascading_composite_array += :C
950
- cascading_composite_array.should == [ :B ]
951
- sub_cascading_composite_array.should == [ :B, :C ]
952
- sub_cascading_composite_array.shift.should == :B
953
- cascading_composite_array.should == [ :B ]
954
- sub_cascading_composite_array.should == [ :C ]
955
-
956
- end
957
-
958
- ############
959
- # slice! #
960
- ############
961
-
962
- it 'can slice elements' do
963
-
964
- cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @configuration_instance, @configuration_name )
965
- sub_cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @sub_configuration_instance, @configuration_name )
966
-
967
- cascading_composite_array += :A
968
- cascading_composite_array.should == [ :A ]
969
- sub_cascading_composite_array.should == [ :A ]
970
-
971
- cascading_composite_array.slice!( 0, 1 ).should == [ :A ]
972
- cascading_composite_array.should == [ ]
973
- sub_cascading_composite_array.should == [ ]
974
-
975
- cascading_composite_array += :B
976
- cascading_composite_array.should == [ :B ]
977
- sub_cascading_composite_array.should == [ :B ]
978
-
979
- sub_cascading_composite_array += :C
980
- cascading_composite_array.should == [ :B ]
981
- sub_cascading_composite_array.should == [ :B, :C ]
982
-
983
- sub_cascading_composite_array.slice!( 0, 1 ).should == [ :B ]
984
- cascading_composite_array.should == [ :B ]
985
- sub_cascading_composite_array.should == [ :C ]
986
-
987
- end
988
-
989
- ###########
990
- # clear #
991
- ###########
992
-
993
- it 'can clear, causing present elements to be excluded' do
994
-
995
- cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @configuration_instance, @configuration_name )
996
- sub_cascading_composite_array = CascadingConfiguration::Array::CompositingArray.new( @sub_configuration_instance, @configuration_name )
997
-
998
- cascading_composite_array += :A
999
- cascading_composite_array.should == [ :A ]
1000
- sub_cascading_composite_array.should == [ :A ]
1001
-
1002
- cascading_composite_array.clear
1003
- cascading_composite_array.should == [ ]
1004
- sub_cascading_composite_array.should == [ ]
1005
-
1006
- cascading_composite_array += :B
1007
- cascading_composite_array.should == [ :B ]
1008
- sub_cascading_composite_array.should == [ :B ]
1009
-
1010
- sub_cascading_composite_array += :C
1011
- cascading_composite_array.should == [ :B ]
1012
- sub_cascading_composite_array.should == [ :B, :C ]
1013
-
1014
- sub_cascading_composite_array.clear
1015
- cascading_composite_array.should == [ :B ]
1016
- sub_cascading_composite_array.should == [ ]
1017
-
1018
- end
1019
-
1020
- end