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