cascading-configuration-array-unique 2.0.4 → 2.1.0

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