external 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/History +7 -0
  2. data/MIT-LICENSE +1 -3
  3. data/README +162 -127
  4. data/lib/external.rb +2 -3
  5. data/lib/external/base.rb +174 -47
  6. data/lib/external/chunkable.rb +131 -105
  7. data/lib/external/enumerable.rb +78 -33
  8. data/lib/external/io.rb +163 -398
  9. data/lib/external/patches/ruby_1_8_io.rb +31 -0
  10. data/lib/external/patches/windows_io.rb +53 -0
  11. data/lib/external/patches/windows_utils.rb +27 -0
  12. data/lib/external/utils.rb +148 -0
  13. data/lib/external_archive.rb +840 -0
  14. data/lib/external_array.rb +57 -0
  15. data/lib/external_index.rb +1053 -0
  16. metadata +42 -58
  17. data/lib/ext_arc.rb +0 -108
  18. data/lib/ext_arr.rb +0 -727
  19. data/lib/ext_ind.rb +0 -1120
  20. data/test/benchmarks/benchmarks_20070918.txt +0 -45
  21. data/test/benchmarks/benchmarks_20070921.txt +0 -91
  22. data/test/benchmarks/benchmarks_20071006.txt +0 -147
  23. data/test/benchmarks/test_copy_file.rb +0 -80
  24. data/test/benchmarks/test_pos_speed.rb +0 -47
  25. data/test/benchmarks/test_read_time.rb +0 -55
  26. data/test/cached_ext_ind_test.rb +0 -219
  27. data/test/check/benchmark_check.rb +0 -441
  28. data/test/check/namespace_conflicts_check.rb +0 -23
  29. data/test/check/pack_check.rb +0 -90
  30. data/test/ext_arc_test.rb +0 -286
  31. data/test/ext_arr/alt_sep.txt +0 -3
  32. data/test/ext_arr/cr_lf_input.txt +0 -3
  33. data/test/ext_arr/input.index +0 -0
  34. data/test/ext_arr/input.txt +0 -1
  35. data/test/ext_arr/inputb.index +0 -0
  36. data/test/ext_arr/inputb.txt +0 -1
  37. data/test/ext_arr/lf_input.txt +0 -3
  38. data/test/ext_arr/lines.txt +0 -19
  39. data/test/ext_arr/without_index.txt +0 -1
  40. data/test/ext_arr_test.rb +0 -534
  41. data/test/ext_ind_test.rb +0 -1472
  42. data/test/external/base_test.rb +0 -74
  43. data/test/external/chunkable_test.rb +0 -182
  44. data/test/external/index/input.index +0 -0
  45. data/test/external/index/inputb.index +0 -0
  46. data/test/external/io_test.rb +0 -414
  47. data/test/external_test_helper.rb +0 -31
  48. data/test/external_test_suite.rb +0 -4
  49. data/test/test_array.rb +0 -1192
@@ -1,31 +0,0 @@
1
- require 'tap'
2
- require 'tap/test/file_methods'
3
- require 'tap/test/subset_methods'
4
-
5
- require File.join(File.dirname(__FILE__), 'test_array.rb')
6
-
7
- class Test::Unit::TestCase
8
- include Tap::Test::SubsetMethods
9
-
10
- # method to duplicate one of the source files to a target file
11
- def dup_file(source_base, target_base)
12
- filepath = tempfile(target_base)
13
- FileUtils.cp(source_base + '.txt', filepath + ".txt")
14
- FileUtils.cp(source_base + '.index', filepath + ".index")
15
-
16
- filepath + ".txt"
17
- end
18
-
19
- #
20
- # The default data
21
- #
22
-
23
- def string
24
- "abcdefgh"
25
- end
26
-
27
- def array
28
- ["a", "b", "c", "d", "e", "f", "g", "h"]
29
- end
30
-
31
- end
@@ -1,4 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '../lib')
2
-
3
- #ENV["ALL"] = 'true'
4
- Dir.glob("./**/*_test.rb").each {|test| require test}
data/test/test_array.rb DELETED
@@ -1,1192 +0,0 @@
1
- require 'test/unit'
2
-
3
- ###########################
4
- # Array methods tests
5
- #
6
- # taken from Ruby 1.9 trunk, revision 13450 (2007-16-2007)
7
- # test/ruby/test_array.rb
8
- #
9
- # run rake diff_test_array to view any differences between
10
- # this and the current test_array
11
- ###########################
12
-
13
- #class TestArray < Test::Unit::TestCase
14
- module TestArray
15
-
16
- # def test_0_literal
17
- # assert_equal([1, 2, 3, 4], [1, 2] + [3, 4])
18
- # assert_equal([1, 2, 1, 2], [1, 2] * 2)
19
- # assert_equal("1:2", [1, 2] * ":")
20
- #
21
- # assert_equal([1, 2].hash, [1, 2].hash)
22
- #
23
- # assert_equal([2,3], [1,2,3] & [2,3,4])
24
- # assert_equal([1,2,3,4], [1,2,3] | [2,3,4])
25
- # assert_equal([1,2,3] - [2,3], [1])
26
- #
27
- # x = [0, 1, 2, 3, 4, 5]
28
- # assert_equal(2, x[2])
29
- # assert_equal([1, 2, 3], x[1..3])
30
- # assert_equal([1, 2, 3], x[1,3])
31
- #
32
- # x[0, 2] = 10
33
- # assert(x[0] == 10 && x[1] == 2)
34
- #
35
- # x[0, 0] = -1
36
- # assert(x[0] == -1 && x[1] == 10)
37
- #
38
- # x[-1, 1] = 20
39
- # assert(x[-1] == 20 && x.pop == 20)
40
- # end
41
- #
42
- # def test_array_andor_0
43
- # assert_equal([2], ([1,2,3]&[2,4,6]))
44
- # assert_equal([1,2,3,4,6], ([1,2,3]|[2,4,6]))
45
- # end
46
- #
47
- # def test_compact_0
48
- # a = [nil, 1, nil, nil, 5, nil, nil]
49
- # assert_equal [1, 5], a.compact
50
- # assert_equal [nil, 1, nil, nil, 5, nil, nil], a
51
- # a.compact!
52
- # assert_equal [1, 5], a
53
- # end
54
- #
55
- # def test_uniq_0
56
- # x = [1, 1, 4, 2, 5, 4, 5, 1, 2]
57
- # x.uniq!
58
- # assert_equal([1, 4, 2, 5], x)
59
- # end
60
- #
61
- # def test_empty_0
62
- # assert_equal true, [].empty?
63
- # assert_equal false, [1].empty?
64
- # assert_equal false, [1, 1, 4, 2, 5, 4, 5, 1, 2].empty?
65
- # end
66
- #
67
- # def test_sort_0
68
- # x = ["it", "came", "to", "pass", "that", "..."]
69
- # x = x.sort.join(" ")
70
- # assert_equal("... came it pass that to", x)
71
- # x = [2,5,3,1,7]
72
- # x.sort!{|a,b| a<=>b} # sort with condition
73
- # assert_equal([1,2,3,5,7], x)
74
- # x.sort!{|a,b| b-a} # reverse sort
75
- # assert_equal([7,5,3,2,1], x)
76
- # end
77
- #
78
- # def test_split_0
79
- # x = "The Boassert of Mormon"
80
- # assert_equal(x.reverse, x.split(//).reverse!.join)
81
- # assert_equal(x.reverse, x.reverse!)
82
- # assert_equal("g:n:i:r:t:s: :e:t:y:b: :1", "1 byte string".split(//).reverse.join(":"))
83
- # x = "a b c d"
84
- # assert_equal(['a', 'b', 'c', 'd'], x.split)
85
- # assert_equal(['a', 'b', 'c', 'd'], x.split(' '))
86
- # end
87
- #
88
- # def test_misc_0
89
- # assert(defined? "a".chomp)
90
- # assert_equal(["a", "b", "c"], "abc".scan(/./))
91
- # assert_equal([["1a"], ["2b"], ["3c"]], "1a2b3c".scan(/(\d.)/))
92
- # # non-greedy match
93
- # assert_equal([["a", "12"], ["b", "22"]], "a=12;b=22".scan(/(.*?)=(\d*);?/))
94
- #
95
- # x = [1]
96
- # assert_equal('1:1:1:1:1', (x * 5).join(":"))
97
- # assert_equal('1', (x * 1).join(":"))
98
- # assert_equal('', (x * 0).join(":"))
99
- #
100
- # *x = *(1..7).to_a
101
- # assert_equal(7, x.size)
102
- # assert_equal([1, 2, 3, 4, 5, 6, 7], x)
103
- #
104
- # x = [1,2,3]
105
- # x[1,0] = x
106
- # assert_equal([1,1,2,3,2,3], x)
107
- #
108
- # x = [1,2,3]
109
- # x[-1,0] = x
110
- # assert_equal([1,2,1,2,3,3], x)
111
- #
112
- # x = [1,2,3]
113
- # x.concat(x)
114
- # assert_equal([1,2,3,1,2,3], x)
115
- #
116
- # x = [1,2,3]
117
- # x.clear
118
- # assert_equal([], x)
119
- #
120
- # x = [1,2,3]
121
- # y = x.dup
122
- # x << 4
123
- # y << 5
124
- # assert_equal([1,2,3,4], x)
125
- # assert_equal([1,2,3,5], y)
126
- # end
127
- #
128
- # def test_beg_end_0
129
- # x = [1, 2, 3, 4, 5]
130
- #
131
- # assert_equal(1, x.first)
132
- # assert_equal([1], x.first(1))
133
- # assert_equal([1, 2, 3], x.first(3))
134
- #
135
- # assert_equal(5, x.last)
136
- # assert_equal([5], x.last(1))
137
- # assert_equal([3, 4, 5], x.last(3))
138
- #
139
- # assert_equal(1, x.shift)
140
- # assert_equal([2, 3, 4], x.shift(3))
141
- # assert_equal([5], x)
142
- #
143
- # assert_equal([2, 3, 4, 5], x.unshift(2, 3, 4))
144
- # assert_equal([1, 2, 3, 4, 5], x.unshift(1))
145
- # assert_equal([1, 2, 3, 4, 5], x)
146
- #
147
- # assert_equal(5, x.pop)
148
- # assert_equal([3, 4], x.pop(2))
149
- # assert_equal([1, 2], x)
150
- #
151
- # assert_equal([1, 2, 3, 4], x.push(3, 4))
152
- # assert_equal([1, 2, 3, 4, 5], x.push(5))
153
- # assert_equal([1, 2, 3, 4, 5], x)
154
- # end
155
- #
156
- # def test_find_all_0
157
- # assert_respond_to([], :find_all)
158
- # assert_respond_to([], :select) # Alias
159
- # assert_equal([], [].find_all{ |obj| obj == "foo"})
160
- #
161
- # x = ["foo", "bar", "baz", "baz", 1, 2, 3, 3, 4]
162
- # assert_equal(["baz","baz"], x.find_all{ |obj| obj == "baz" })
163
- # assert_equal([3,3], x.find_all{ |obj| obj == 3 })
164
- # end
165
- #
166
- # def test_fill_0
167
- # assert_equal([-1, -1, -1, -1, -1, -1], [0, 1, 2, 3, 4, 5].fill(-1))
168
- # assert_equal([0, 1, 2, -1, -1, -1], [0, 1, 2, 3, 4, 5].fill(-1, 3))
169
- # assert_equal([0, 1, 2, -1, -1, 5], [0, 1, 2, 3, 4, 5].fill(-1, 3, 2))
170
- # assert_equal([0, 1, 2, -1, -1, -1, -1, -1], [0, 1, 2, 3, 4, 5].fill(-1, 3, 5))
171
- # assert_equal([0, 1, -1, -1, 4, 5], [0, 1, 2, 3, 4, 5].fill(-1, 2, 2))
172
- # assert_equal([0, 1, -1, -1, -1, -1, -1], [0, 1, 2, 3, 4, 5].fill(-1, 2, 5))
173
- # assert_equal([0, 1, 2, 3, -1, 5], [0, 1, 2, 3, 4, 5].fill(-1, -2, 1))
174
- # assert_equal([0, 1, 2, 3, -1, -1, -1], [0, 1, 2, 3, 4, 5].fill(-1, -2, 3))
175
- # assert_equal([0, 1, 2, -1, -1, 5], [0, 1, 2, 3, 4, 5].fill(-1, 3..4))
176
- # assert_equal([0, 1, 2, -1, 4, 5], [0, 1, 2, 3, 4, 5].fill(-1, 3...4))
177
- # assert_equal([0, 1, -1, -1, -1, 5], [0, 1, 2, 3, 4, 5].fill(-1, 2..-2))
178
- # assert_equal([0, 1, -1, -1, 4, 5], [0, 1, 2, 3, 4, 5].fill(-1, 2...-2))
179
- # assert_equal([10, 11, 12, 13, 14, 15], [0, 1, 2, 3, 4, 5].fill{|i| i+10})
180
- # assert_equal([0, 1, 2, 13, 14, 15], [0, 1, 2, 3, 4, 5].fill(3){|i| i+10})
181
- # assert_equal([0, 1, 2, 13, 14, 5], [0, 1, 2, 3, 4, 5].fill(3, 2){|i| i+10})
182
- # assert_equal([0, 1, 2, 13, 14, 15, 16, 17], [0, 1, 2, 3, 4, 5].fill(3, 5){|i| i+10})
183
- # assert_equal([0, 1, 2, 13, 14, 5], [0, 1, 2, 3, 4, 5].fill(3..4){|i| i+10})
184
- # assert_equal([0, 1, 2, 13, 4, 5], [0, 1, 2, 3, 4, 5].fill(3...4){|i| i+10})
185
- # assert_equal([0, 1, 12, 13, 14, 5], [0, 1, 2, 3, 4, 5].fill(2..-2){|i| i+10})
186
- # assert_equal([0, 1, 12, 13, 4, 5], [0, 1, 2, 3, 4, 5].fill(2...-2){|i| i+10})
187
- # end
188
-
189
- # From rubicon
190
-
191
- # def setup
192
- # @cls = Array
193
- # end
194
-
195
- def test_00_new
196
- a = @cls.new()
197
- assert_instance_of(@cls, a)
198
- assert_equal(0, a.length)
199
- assert_nil(a[0])
200
- end
201
-
202
- def test_01_square_brackets
203
- a = @cls[ 5, 4, 3, 2, 1 ]
204
- assert_instance_of(@cls, a)
205
- assert_equal(5, a.length)
206
- 5.times { |i| assert_equal(5-i, a[i]) }
207
- assert_nil(a[6])
208
- end
209
-
210
- # def test_AND # '&'
211
- # assert_equal(@cls[1, 3], @cls[ 1, 1, 3, 5 ] & @cls[ 1, 2, 3 ])
212
- # assert_equal(@cls[], @cls[ 1, 1, 3, 5 ] & @cls[ ])
213
- # assert_equal(@cls[], @cls[ ] & @cls[ 1, 2, 3 ])
214
- # assert_equal(@cls[], @cls[ 1, 2, 3 ] & @cls[ 4, 5, 6 ])
215
- # end
216
- #
217
- # def test_MUL # '*'
218
- # assert_equal(@cls[], @cls[]*3)
219
- # assert_equal(@cls[1, 1, 1], @cls[1]*3)
220
- # assert_equal(@cls[1, 2, 1, 2, 1, 2], @cls[1, 2]*3)
221
- # assert_equal(@cls[], @cls[1, 2, 3] * 0)
222
- # assert_raise(ArgumentError) { @cls[1, 2]*(-3) }
223
- #
224
- # assert_equal('1-2-3-4-5', @cls[1, 2, 3, 4, 5] * '-')
225
- # assert_equal('12345', @cls[1, 2, 3, 4, 5] * '')
226
- #
227
- # end
228
- #
229
- def test_PLUS # '+'
230
- assert_equal(@cls[], @cls[] + @cls[])
231
- assert_equal(@cls[1], @cls[1] + @cls[])
232
- assert_equal(@cls[1], @cls[] + @cls[1])
233
- assert_equal(@cls[1, 1], @cls[1] + @cls[1])
234
- assert_equal(@cls['cat', 'dog', 1, 2, 3], %w(cat dog) + (1..3).to_a)
235
- end
236
- #
237
- # def test_MINUS # '-'
238
- # assert_equal(@cls[], @cls[1] - @cls[1])
239
- # assert_equal(@cls[1], @cls[1, 2, 3, 4, 5] - @cls[2, 3, 4, 5])
240
- # # Ruby 1.8 feature change
241
- # #assert_equal(@cls[1], @cls[1, 2, 1, 3, 1, 4, 1, 5] - @cls[2, 3, 4, 5])
242
- # assert_equal(@cls[1, 1, 1, 1], @cls[1, 2, 1, 3, 1, 4, 1, 5] - @cls[2, 3, 4, 5])
243
- # a = @cls[]
244
- # 1000.times { a << 1 }
245
- # assert_equal(1000, a.length)
246
- # #assert_equal(@cls[1], a - @cls[2])
247
- # assert_equal(@cls[1] * 1000, a - @cls[2])
248
- # #assert_equal(@cls[1], @cls[1, 2, 1] - @cls[2])
249
- # assert_equal(@cls[1, 1], @cls[1, 2, 1] - @cls[2])
250
- # assert_equal(@cls[1, 2, 3], @cls[1, 2, 3] - @cls[4, 5, 6])
251
- # end
252
-
253
- def test_LSHIFT # '<<'
254
- a = @cls[]
255
- a << 1
256
- assert_equal(@cls[1], a)
257
- a << 2 << 3
258
- assert_equal(@cls[1, 2, 3], a)
259
- a << nil << 'cat'
260
- assert_equal(@cls[1, 2, 3, nil, 'cat'], a)
261
- a << a
262
- assert_equal(@cls[1, 2, 3, nil, 'cat', a], a)
263
- end
264
-
265
- def test_CMP # '<=>'
266
- assert_equal(0, @cls[] <=> @cls[])
267
- assert_equal(0, @cls[1] <=> @cls[1])
268
- assert_equal(0, @cls[1, 2, 3, 'cat'] <=> @cls[1, 2, 3, 'cat'])
269
- assert_equal(-1, @cls[] <=> @cls[1])
270
- assert_equal(1, @cls[1] <=> @cls[])
271
- assert_equal(-1, @cls[1, 2, 3] <=> @cls[1, 2, 3, 'cat'])
272
- assert_equal(1, @cls[1, 2, 3, 'cat'] <=> @cls[1, 2, 3])
273
- assert_equal(-1, @cls[1, 2, 3, 'cat'] <=> @cls[1, 2, 3, 'dog'])
274
- assert_equal(1, @cls[1, 2, 3, 'dog'] <=> @cls[1, 2, 3, 'cat'])
275
- end
276
-
277
- def test_EQUAL # '=='
278
- assert(@cls[] == @cls[])
279
- assert(@cls[1] == @cls[1])
280
- assert(@cls[1, 1, 2, 2] == @cls[1, 1, 2, 2])
281
- assert(@cls[1.0, 1.0, 2.0, 2.0] == @cls[1, 1, 2, 2])
282
- end
283
-
284
- # def test_VERY_EQUAL # '==='
285
- # assert(@cls[] === @cls[])
286
- # assert(@cls[1] === @cls[1])
287
- # assert(@cls[1, 1, 2, 2] === @cls[1, 1, 2, 2])
288
- # assert(@cls[1.0, 1.0, 2.0, 2.0] === @cls[1, 1, 2, 2])
289
- # end
290
- #
291
- def test_AREF # '[]'
292
- a = @cls[*(1..100).to_a]
293
-
294
- assert_equal(1, a[0])
295
- assert_equal(100, a[99])
296
- assert_nil(a[100])
297
- assert_equal(100, a[-1])
298
- assert_equal(99, a[-2])
299
- assert_equal(1, a[-100])
300
- assert_nil(a[-101])
301
- assert_nil(a[-101,0])
302
- assert_nil(a[-101,1])
303
- assert_nil(a[-101,-1])
304
- assert_nil(a[10,-1])
305
-
306
- assert_equal(@cls[1], a[0,1])
307
- assert_equal(@cls[100], a[99,1])
308
- assert_equal(@cls[], a[100,1])
309
- assert_equal(@cls[100], a[99,100])
310
- assert_equal(@cls[100], a[-1,1])
311
- assert_equal(@cls[99], a[-2,1])
312
- assert_equal(@cls[], a[-100,0])
313
- assert_equal(@cls[1], a[-100,1])
314
-
315
- assert_equal(@cls[10, 11, 12], a[9, 3])
316
- assert_equal(@cls[10, 11, 12], a[-91, 3])
317
-
318
- assert_equal(@cls[1], a[0..0])
319
- assert_equal(@cls[100], a[99..99])
320
- assert_equal(@cls[], a[100..100])
321
- assert_equal(@cls[100], a[99..200])
322
- assert_equal(@cls[100], a[-1..-1])
323
- assert_equal(@cls[99], a[-2..-2])
324
-
325
- assert_equal(@cls[10, 11, 12], a[9..11])
326
- assert_equal(@cls[10, 11, 12], a[-91..-89])
327
-
328
- assert_nil(a[10, -3])
329
- # Ruby 1.8 feature change:
330
- # Array#[size..x] returns [] instead of nil.
331
- #assert_nil(a[10..7])
332
- assert_equal [], a[10..7]
333
-
334
- assert_raise(TypeError) {a['cat']}
335
- end
336
-
337
- def test_ASET # '[]='
338
- a = @cls[*(0..99).to_a]
339
- assert_equal(0, a[0] = 0)
340
- assert_equal(@cls[0] + @cls[*(1..99).to_a], a)
341
-
342
- a = @cls[*(0..99).to_a]
343
- assert_equal(0, a[10,10] = 0)
344
- assert_equal(@cls[*(0..9).to_a] + @cls[0] + @cls[*(20..99).to_a], a)
345
-
346
- a = @cls[*(0..99).to_a]
347
- assert_equal(0, a[-1] = 0)
348
- assert_equal(@cls[*(0..98).to_a] + @cls[0], a)
349
-
350
- a = @cls[*(0..99).to_a]
351
- assert_equal(0, a[-10, 10] = 0)
352
- assert_equal(@cls[*(0..89).to_a] + @cls[0], a)
353
-
354
- a = @cls[*(0..99).to_a]
355
- assert_equal(0, a[0,1000] = 0)
356
- assert_equal(@cls[0] , a)
357
-
358
- a = @cls[*(0..99).to_a]
359
- assert_equal(0, a[10..19] = 0)
360
- assert_equal(@cls[*(0..9).to_a] + @cls[0] + @cls[*(20..99).to_a], a)
361
-
362
- b = @cls[*%w( a b c )]
363
- a = @cls[*(0..99).to_a]
364
- assert_equal(b, a[0,1] = b)
365
- assert_equal(b + @cls[*(1..99).to_a], a)
366
-
367
- a = @cls[*(0..99).to_a]
368
- assert_equal(b, a[10,10] = b)
369
- assert_equal(@cls[*(0..9).to_a] + b + @cls[*(20..99).to_a], a)
370
-
371
- a = @cls[*(0..99).to_a]
372
- assert_equal(b, a[-1, 1] = b)
373
- assert_equal(@cls[*(0..98).to_a] + b, a)
374
-
375
- a = @cls[*(0..99).to_a]
376
- assert_equal(b, a[-10, 10] = b)
377
- assert_equal(@cls[*(0..89).to_a] + b, a)
378
-
379
- a = @cls[*(0..99).to_a]
380
- assert_equal(b, a[0,1000] = b)
381
- assert_equal(b , a)
382
-
383
- a = @cls[*(0..99).to_a]
384
- assert_equal(b, a[10..19] = b)
385
- assert_equal(@cls[*(0..9).to_a] + b + @cls[*(20..99).to_a], a)
386
-
387
- # Ruby 1.8 feature change:
388
- # assigning nil does not remove elements.
389
- =begin
390
- a = @cls[*(0..99).to_a]
391
- assert_equal(nil, a[0,1] = nil)
392
- assert_equal(@cls[*(1..99).to_a], a)
393
-
394
- a = @cls[*(0..99).to_a]
395
- assert_equal(nil, a[10,10] = nil)
396
- assert_equal(@cls[*(0..9).to_a] + @cls[*(20..99).to_a], a)
397
-
398
- a = @cls[*(0..99).to_a]
399
- assert_equal(nil, a[-1, 1] = nil)
400
- assert_equal(@cls[*(0..98).to_a], a)
401
-
402
- a = @cls[*(0..99).to_a]
403
- assert_equal(nil, a[-10, 10] = nil)
404
- assert_equal(@cls[*(0..89).to_a], a)
405
-
406
- a = @cls[*(0..99).to_a]
407
- assert_equal(nil, a[0,1000] = nil)
408
- assert_equal(@cls[] , a)
409
-
410
- a = @cls[*(0..99).to_a]
411
- assert_equal(nil, a[10..19] = nil)
412
- assert_equal(@cls[*(0..9).to_a] + @cls[*(20..99).to_a], a)
413
- =end
414
-
415
- a = @cls[1, 2, 3]
416
- a[1, 0] = a
417
- assert_equal([1, 1, 2, 3, 2, 3], a)
418
-
419
- a = @cls[1, 2, 3]
420
- a[-1, 0] = a
421
- assert_equal([1, 2, 1, 2, 3, 3], a)
422
- end
423
-
424
- # def test_assoc
425
- # a1 = @cls[*%w( cat feline )]
426
- # a2 = @cls[*%w( dog canine )]
427
- # a3 = @cls[*%w( mule asinine )]
428
- #
429
- # a = @cls[ a1, a2, a3 ]
430
- #
431
- # assert_equal(a1, a.assoc('cat'))
432
- # assert_equal(a3, a.assoc('mule'))
433
- # assert_equal(nil, a.assoc('asinine'))
434
- # assert_equal(nil, a.assoc('wombat'))
435
- # assert_equal(nil, a.assoc(1..2))
436
- # end
437
-
438
- def test_at
439
- a = @cls[*(0..99).to_a]
440
- assert_equal(0, a.at(0))
441
- assert_equal(10, a.at(10))
442
- assert_equal(99, a.at(99))
443
- assert_equal(nil, a.at(100))
444
- assert_equal(99, a.at(-1))
445
- assert_equal(0, a.at(-100))
446
- assert_equal(nil, a.at(-101))
447
- assert_raise(TypeError) { a.at('cat') }
448
- end
449
-
450
- def test_clear
451
- a = @cls[1, 2, 3]
452
- b = a.clear
453
- assert_equal(@cls[], a)
454
- assert_equal(@cls[], b)
455
- assert_equal(a.__id__, b.__id__)
456
- end
457
- #
458
- # def test_clone
459
- # for taint in [ false, true ]
460
- # for frozen in [ false, true ]
461
- # a = @cls[*(0..99).to_a]
462
- # a.taint if taint
463
- # a.freeze if frozen
464
- # b = a.clone
465
- #
466
- # assert_equal(a, b)
467
- # assert(a.__id__ != b.__id__)
468
- # assert_equal(a.frozen?, b.frozen?)
469
- # assert_equal(a.tainted?, b.tainted?)
470
- # end
471
- # end
472
- # end
473
- #
474
- # def test_collect
475
- # a = @cls[ 1, 'cat', 1..1 ]
476
- # assert_equal([ Fixnum, String, Range], a.collect {|e| e.class} )
477
- # assert_equal([ 99, 99, 99], a.collect { 99 } )
478
- #
479
- # assert_equal([], @cls[].collect { 99 })
480
- #
481
- # # Ruby 1.9 feature change:
482
- # # Enumerable#collect without block returns an Enumerator.
483
- # #assert_equal([1, 2, 3], @cls[1, 2, 3].collect)
484
- # assert_kind_of Enumerable::Enumerator, @cls[1, 2, 3].collect
485
- # end
486
- #
487
- # # also update map!
488
- # def test_collect!
489
- # a = @cls[ 1, 'cat', 1..1 ]
490
- # assert_equal([ Fixnum, String, Range], a.collect! {|e| e.class} )
491
- # assert_equal([ Fixnum, String, Range], a)
492
- #
493
- # a = @cls[ 1, 'cat', 1..1 ]
494
- # assert_equal([ 99, 99, 99], a.collect! { 99 } )
495
- # assert_equal([ 99, 99, 99], a)
496
- #
497
- # a = @cls[ ]
498
- # assert_equal([], a.collect! { 99 })
499
- # assert_equal([], a)
500
- # end
501
- #
502
- # def test_compact
503
- # a = @cls[ 1, nil, nil, 2, 3, nil, 4 ]
504
- # assert_equal(@cls[1, 2, 3, 4], a.compact)
505
- #
506
- # a = @cls[ nil, 1, nil, 2, 3, nil, 4 ]
507
- # assert_equal(@cls[1, 2, 3, 4], a.compact)
508
- #
509
- # a = @cls[ 1, nil, nil, 2, 3, nil, 4, nil ]
510
- # assert_equal(@cls[1, 2, 3, 4], a.compact)
511
- #
512
- # a = @cls[ 1, 2, 3, 4 ]
513
- # assert_equal(@cls[1, 2, 3, 4], a.compact)
514
- # end
515
- #
516
- # def test_compact!
517
- # a = @cls[ 1, nil, nil, 2, 3, nil, 4 ]
518
- # assert_equal(@cls[1, 2, 3, 4], a.compact!)
519
- # assert_equal(@cls[1, 2, 3, 4], a)
520
- #
521
- # a = @cls[ nil, 1, nil, 2, 3, nil, 4 ]
522
- # assert_equal(@cls[1, 2, 3, 4], a.compact!)
523
- # assert_equal(@cls[1, 2, 3, 4], a)
524
- #
525
- # a = @cls[ 1, nil, nil, 2, 3, nil, 4, nil ]
526
- # assert_equal(@cls[1, 2, 3, 4], a.compact!)
527
- # assert_equal(@cls[1, 2, 3, 4], a)
528
- #
529
- # a = @cls[ 1, 2, 3, 4 ]
530
- # assert_equal(nil, a.compact!)
531
- # assert_equal(@cls[1, 2, 3, 4], a)
532
- # end
533
- #
534
- def test_concat
535
- assert_equal(@cls[1, 2, 3, 4], @cls[1, 2].concat(@cls[3, 4]))
536
- assert_equal(@cls[1, 2, 3, 4], @cls[].concat(@cls[1, 2, 3, 4]))
537
- assert_equal(@cls[1, 2, 3, 4], @cls[1, 2, 3, 4].concat(@cls[]))
538
- assert_equal(@cls[], @cls[].concat(@cls[]))
539
- assert_equal(@cls[@cls[1, 2], @cls[3, 4]], @cls[@cls[1, 2]].concat(@cls[@cls[3, 4]]))
540
-
541
- a = @cls[1, 2, 3]
542
- a.concat(a)
543
- assert_equal([1, 2, 3, 1, 2, 3], a)
544
- end
545
- #
546
- # def test_delete
547
- # a = @cls[*('cab'..'cat').to_a]
548
- # assert_equal('cap', a.delete('cap'))
549
- # assert_equal(@cls[*('cab'..'cao').to_a] + @cls[*('caq'..'cat').to_a], a)
550
- #
551
- # a = @cls[*('cab'..'cat').to_a]
552
- # assert_equal('cab', a.delete('cab'))
553
- # assert_equal(@cls[*('cac'..'cat').to_a], a)
554
- #
555
- # a = @cls[*('cab'..'cat').to_a]
556
- # assert_equal('cat', a.delete('cat'))
557
- # assert_equal(@cls[*('cab'..'cas').to_a], a)
558
- #
559
- # a = @cls[*('cab'..'cat').to_a]
560
- # assert_equal(nil, a.delete('cup'))
561
- # assert_equal(@cls[*('cab'..'cat').to_a], a)
562
- #
563
- # a = @cls[*('cab'..'cat').to_a]
564
- # assert_equal(99, a.delete('cup') { 99 } )
565
- # assert_equal(@cls[*('cab'..'cat').to_a], a)
566
- # end
567
- #
568
- # def test_delete_at
569
- # a = @cls[*(1..5).to_a]
570
- # assert_equal(3, a.delete_at(2))
571
- # assert_equal(@cls[1, 2, 4, 5], a)
572
- #
573
- # a = @cls[*(1..5).to_a]
574
- # assert_equal(4, a.delete_at(-2))
575
- # assert_equal(@cls[1, 2, 3, 5], a)
576
- #
577
- # a = @cls[*(1..5).to_a]
578
- # assert_equal(nil, a.delete_at(5))
579
- # assert_equal(@cls[1, 2, 3, 4, 5], a)
580
- #
581
- # a = @cls[*(1..5).to_a]
582
- # assert_equal(nil, a.delete_at(-6))
583
- # assert_equal(@cls[1, 2, 3, 4, 5], a)
584
- # end
585
- #
586
- # # also reject!
587
- # def test_delete_if
588
- # a = @cls[ 1, 2, 3, 4, 5 ]
589
- # assert_equal(a, a.delete_if { false })
590
- # assert_equal(@cls[1, 2, 3, 4, 5], a)
591
- #
592
- # a = @cls[ 1, 2, 3, 4, 5 ]
593
- # assert_equal(a, a.delete_if { true })
594
- # assert_equal(@cls[], a)
595
- #
596
- # a = @cls[ 1, 2, 3, 4, 5 ]
597
- # assert_equal(a, a.delete_if { |i| i > 3 })
598
- # assert_equal(@cls[1, 2, 3], a)
599
- # end
600
- #
601
- # def test_dup
602
- # for taint in [ false, true ]
603
- # for frozen in [ false, true ]
604
- # a = @cls[*(0..99).to_a]
605
- # a.taint if taint
606
- # a.freeze if frozen
607
- # b = a.dup
608
- #
609
- # assert_equal(a, b)
610
- # assert(a.__id__ != b.__id__)
611
- # assert_equal(false, b.frozen?)
612
- # assert_equal(a.tainted?, b.tainted?)
613
- # end
614
- # end
615
- # end
616
- #
617
- def test_each
618
- a = @cls[*%w( ant bat cat dog )]
619
- i = 0
620
- a.each { |e|
621
- assert_equal(a[i], e)
622
- i += 1
623
- }
624
- assert_equal(4, i)
625
-
626
- a = @cls[]
627
- i = 0
628
- a.each { |e|
629
- assert_equal(a[i], e)
630
- i += 1
631
- }
632
- assert_equal(0, i)
633
-
634
- assert_equal(a, a.each {})
635
- end
636
-
637
- def test_each_index
638
- a = @cls[*%w( ant bat cat dog )]
639
- i = 0
640
- a.each_index { |ind|
641
- assert_equal(i, ind)
642
- i += 1
643
- }
644
- assert_equal(4, i)
645
-
646
- a = @cls[]
647
- i = 0
648
- a.each_index { |ind|
649
- assert_equal(i, ind)
650
- i += 1
651
- }
652
- assert_equal(0, i)
653
-
654
- assert_equal(a, a.each_index {})
655
- end
656
-
657
- def test_empty?
658
- assert(@cls[].empty?)
659
- assert(!@cls[1].empty?)
660
- end
661
-
662
- def test_eql?
663
- assert(@cls[].eql?(@cls[]))
664
- assert(@cls[1].eql?(@cls[1]))
665
- assert(@cls[1, 1, 2, 2].eql?(@cls[1, 1, 2, 2]))
666
- assert(!@cls[1.0, 1.0, 2.0, 2.0].eql?(@cls[1, 1, 2, 2]))
667
- end
668
- #
669
- # def test_fill
670
- # assert_equal(@cls[], @cls[].fill(99))
671
- # assert_equal(@cls[], @cls[].fill(99, 0))
672
- # assert_equal(@cls[99], @cls[].fill(99, 0, 1))
673
- # assert_equal(@cls[99], @cls[].fill(99, 0..0))
674
- #
675
- # assert_equal(@cls[99], @cls[1].fill(99))
676
- # assert_equal(@cls[99], @cls[1].fill(99, 0))
677
- # assert_equal(@cls[99], @cls[1].fill(99, 0, 1))
678
- # assert_equal(@cls[99], @cls[1].fill(99, 0..0))
679
- #
680
- # assert_equal(@cls[99, 99], @cls[1, 2].fill(99))
681
- # assert_equal(@cls[99, 99], @cls[1, 2].fill(99, 0))
682
- # assert_equal(@cls[99, 99], @cls[1, 2].fill(99, nil))
683
- # assert_equal(@cls[1, 99], @cls[1, 2].fill(99, 1, nil))
684
- # assert_equal(@cls[99, 2], @cls[1, 2].fill(99, 0, 1))
685
- # assert_equal(@cls[99, 2], @cls[1, 2].fill(99, 0..0))
686
- # end
687
- #
688
- def test_first
689
- assert_equal(3, @cls[3, 4, 5].first)
690
- assert_equal(nil, @cls[].first)
691
- end
692
-
693
- # def test_flatten
694
- # a1 = @cls[ 1, 2, 3]
695
- # a2 = @cls[ 5, 6 ]
696
- # a3 = @cls[ 4, a2 ]
697
- # a4 = @cls[ a1, a3 ]
698
- # assert_equal(@cls[1, 2, 3, 4, 5, 6], a4.flatten)
699
- # assert_equal(@cls[ a1, a3], a4)
700
- #
701
- # a5 = @cls[ a1, @cls[], a3 ]
702
- # assert_equal(@cls[1, 2, 3, 4, 5, 6], a5.flatten)
703
- # assert_equal(@cls[], @cls[].flatten)
704
- # assert_equal(@cls[],
705
- # @cls[@cls[@cls[@cls[],@cls[]],@cls[@cls[]],@cls[]],@cls[@cls[@cls[]]]].flatten)
706
- #
707
- # assert_raise(TypeError, "[ruby-dev:31197]") { [[]].flatten("") }
708
- # end
709
- #
710
- # def test_flatten!
711
- # a1 = @cls[ 1, 2, 3]
712
- # a2 = @cls[ 5, 6 ]
713
- # a3 = @cls[ 4, a2 ]
714
- # a4 = @cls[ a1, a3 ]
715
- # assert_equal(@cls[1, 2, 3, 4, 5, 6], a4.flatten!)
716
- # assert_equal(@cls[1, 2, 3, 4, 5, 6], a4)
717
- #
718
- # a5 = @cls[ a1, @cls[], a3 ]
719
- # assert_equal(@cls[1, 2, 3, 4, 5, 6], a5.flatten!)
720
- # assert_equal(@cls[1, 2, 3, 4, 5, 6], a5)
721
- #
722
- # assert_equal(@cls[], @cls[].flatten)
723
- # assert_equal(@cls[],
724
- # @cls[@cls[@cls[@cls[],@cls[]],@cls[@cls[]],@cls[]],@cls[@cls[@cls[]]]].flatten)
725
- # end
726
- #
727
- # def test_hash
728
- # a1 = @cls[ 'cat', 'dog' ]
729
- # a2 = @cls[ 'cat', 'dog' ]
730
- # a3 = @cls[ 'dog', 'cat' ]
731
- # assert(a1.hash == a2.hash)
732
- # assert(a1.hash != a3.hash)
733
- # end
734
- #
735
- # def test_include?
736
- # a = @cls[ 'cat', 99, /a/, @cls[ 1, 2, 3] ]
737
- # assert(a.include?('cat'))
738
- # assert(a.include?(99))
739
- # assert(a.include?(/a/))
740
- # assert(a.include?([1,2,3]))
741
- # assert(!a.include?('ca'))
742
- # assert(!a.include?([1,2]))
743
- # end
744
- #
745
- # def test_index
746
- # a = @cls[ 'cat', 99, /a/, 99, @cls[ 1, 2, 3] ]
747
- # assert_equal(0, a.index('cat'))
748
- # assert_equal(1, a.index(99))
749
- # assert_equal(4, a.index([1,2,3]))
750
- # assert_nil(a.index('ca'))
751
- # assert_nil(a.index([1,2]))
752
- # end
753
- #
754
- # def test_values_at
755
- # a = @cls[*('a'..'j').to_a]
756
- # assert_equal(@cls['a', 'c', 'e'], a.values_at(0, 2, 4))
757
- # assert_equal(@cls['j', 'h', 'f'], a.values_at(-1, -3, -5))
758
- # assert_equal(@cls['h', nil, 'a'], a.values_at(-3, 99, 0))
759
- # end
760
- #
761
- # def test_join
762
- # $, = ""
763
- # a = @cls[]
764
- # assert_equal("", a.join)
765
- # assert_equal("", a.join(','))
766
- #
767
- # $, = ""
768
- # a = @cls[1, 2]
769
- # assert_equal("12", a.join)
770
- # assert_equal("1,2", a.join(','))
771
- #
772
- # $, = ""
773
- # a = @cls[1, 2, 3]
774
- # assert_equal("123", a.join)
775
- # assert_equal("1,2,3", a.join(','))
776
- #
777
- # $, = ":"
778
- # a = @cls[1, 2, 3]
779
- # assert_equal("1:2:3", a.join)
780
- # assert_equal("1,2,3", a.join(','))
781
- #
782
- # $, = ""
783
- # end
784
- #
785
- def test_last
786
- assert_equal(nil, @cls[].last)
787
- assert_equal(1, @cls[1].last)
788
- assert_equal(99, @cls[*(3..99).to_a].last)
789
- end
790
-
791
- def test_length
792
- assert_equal(0, @cls[].length)
793
- assert_equal(1, @cls[1].length)
794
- assert_equal(2, @cls[1, nil].length)
795
- assert_equal(2, @cls[nil, 1].length)
796
- assert_equal(234, @cls[*(0..233).to_a].length)
797
- end
798
- #
799
- # # also update collect!
800
- # def test_map!
801
- # a = @cls[ 1, 'cat', 1..1 ]
802
- # assert_equal(@cls[ Fixnum, String, Range], a.map! {|e| e.class} )
803
- # assert_equal(@cls[ Fixnum, String, Range], a)
804
- #
805
- # a = @cls[ 1, 'cat', 1..1 ]
806
- # assert_equal(@cls[ 99, 99, 99], a.map! { 99 } )
807
- # assert_equal(@cls[ 99, 99, 99], a)
808
- #
809
- # a = @cls[ ]
810
- # assert_equal(@cls[], a.map! { 99 })
811
- # assert_equal(@cls[], a)
812
- # end
813
- #
814
- # def test_nitems
815
- # assert_equal(0, @cls[].nitems)
816
- # assert_equal(1, @cls[1].nitems)
817
- # assert_equal(1, @cls[1, nil].nitems)
818
- # assert_equal(1, @cls[nil, 1].nitems)
819
- # assert_equal(3, @cls[1, nil, nil, 2, nil, 3, nil].nitems)
820
- # end
821
- #
822
- # def test_pack
823
- # a = @cls[*%w( cat wombat x yy)]
824
- # assert_equal("catwomx yy ", a.pack("A3A3A3A3"))
825
- # assert_equal("cat", a.pack("A*"))
826
- # assert_equal("cwx yy ", a.pack("A3@1A3@2A3A3"))
827
- # assert_equal("catwomx\000\000yy\000", a.pack("a3a3a3a3"))
828
- # assert_equal("cat", a.pack("a*"))
829
- # assert_equal("ca", a.pack("a2"))
830
- # assert_equal("cat\000\000", a.pack("a5"))
831
- #
832
- # assert_equal("\x61", @cls["01100001"].pack("B8"))
833
- # assert_equal("\x61", @cls["01100001"].pack("B*"))
834
- # assert_equal("\x61", @cls["0110000100110111"].pack("B8"))
835
- # assert_equal("\x61\x37", @cls["0110000100110111"].pack("B16"))
836
- # assert_equal("\x61\x37", @cls["01100001", "00110111"].pack("B8B8"))
837
- # assert_equal("\x60", @cls["01100001"].pack("B4"))
838
- # assert_equal("\x40", @cls["01100001"].pack("B2"))
839
- #
840
- # assert_equal("\x86", @cls["01100001"].pack("b8"))
841
- # assert_equal("\x86", @cls["01100001"].pack("b*"))
842
- # assert_equal("\x86", @cls["0110000100110111"].pack("b8"))
843
- # assert_equal("\x86\xec", @cls["0110000100110111"].pack("b16"))
844
- # assert_equal("\x86\xec", @cls["01100001", "00110111"].pack("b8b8"))
845
- # assert_equal("\x06", @cls["01100001"].pack("b4"))
846
- # assert_equal("\x02", @cls["01100001"].pack("b2"))
847
- #
848
- # assert_equal("ABC", @cls[ 65, 66, 67 ].pack("C3"))
849
- # assert_equal("\377BC", @cls[ -1, 66, 67 ].pack("C*"))
850
- # assert_equal("ABC", @cls[ 65, 66, 67 ].pack("c3"))
851
- # assert_equal("\377BC", @cls[ -1, 66, 67 ].pack("c*"))
852
- #
853
- #
854
- # assert_equal("AB\n\x10", @cls["4142", "0a", "12"].pack("H4H2H1"))
855
- # assert_equal("AB\n\x02", @cls["1424", "a0", "21"].pack("h4h2h1"))
856
- #
857
- # assert_equal("abc=02def=\ncat=\n=01=\n",
858
- # @cls["abc\002def", "cat", "\001"].pack("M9M3M4"))
859
- #
860
- # assert_equal("aGVsbG8K\n", @cls["hello\n"].pack("m"))
861
- # assert_equal(",:&5L;&\\*:&5L;&\\*\n", @cls["hello\nhello\n"].pack("u"))
862
- #
863
- # assert_equal("\xc2\xa9B\xe2\x89\xa0", @cls[0xa9, 0x42, 0x2260].pack("U*"))
864
- #
865
- #
866
- # format = "c2x5CCxsdils_l_a6";
867
- # # Need the expression in here to force ary[5] to be numeric. This avoids
868
- # # test2 failing because ary2 goes str->numeric->str and ary does not.
869
- # ary = [1, -100, 127, 128, 32767, 987.654321098/100.0,
870
- # 12345, 123456, -32767, -123456, "abcdef"]
871
- # x = ary.pack(format)
872
- # ary2 = x.unpack(format)
873
- #
874
- # assert_equal(ary.length, ary2.length)
875
- # assert_equal(ary.join(':'), ary2.join(':'))
876
- # assert_not_nil(x =~ /def/)
877
- #
878
- # =begin
879
- # skipping "Not tested:
880
- # D,d & double-precision float, native format\\
881
- # E & double-precision float, little-endian byte order\\
882
- # e & single-precision float, little-endian byte order\\
883
- # F,f & single-precision float, native format\\
884
- # G & double-precision float, network (big-endian) byte order\\
885
- # g & single-precision float, network (big-endian) byte order\\
886
- # I & unsigned integer\\
887
- # i & integer\\
888
- # L & unsigned long\\
889
- # l & long\\
890
- #
891
- # N & long, network (big-endian) byte order\\
892
- # n & short, network (big-endian) byte-order\\
893
- # P & pointer to a structure (fixed-length string)\\
894
- # p & pointer to a null-terminated string\\
895
- # S & unsigned short\\
896
- # s & short\\
897
- # V & long, little-endian byte order\\
898
- # v & short, little-endian byte order\\
899
- # X & back up a byte\\
900
- # x & null byte\\
901
- # Z & ASCII string (null padded, count is width)\\
902
- # "
903
- # =end
904
- # end
905
- #
906
- # def test_pop
907
- # a = @cls[ 'cat', 'dog' ]
908
- # assert_equal('dog', a.pop)
909
- # assert_equal(@cls['cat'], a)
910
- # assert_equal('cat', a.pop)
911
- # assert_equal(@cls[], a)
912
- # assert_nil(a.pop)
913
- # assert_equal(@cls[], a)
914
- # end
915
- #
916
- # def test_push
917
- # a = @cls[1, 2, 3]
918
- # assert_equal(@cls[1, 2, 3, 4, 5], a.push(4, 5))
919
- # assert_equal(@cls[1, 2, 3, 4, 5, nil], a.push(nil))
920
- # # Ruby 1.8 feature:
921
- # # Array#push accepts any number of arguments.
922
- # #assert_raise(ArgumentError, "a.push()") { a.push() }
923
- # a.push
924
- # assert_equal @cls[1, 2, 3, 4, 5, nil], a
925
- # a.push 6, 7
926
- # assert_equal @cls[1, 2, 3, 4, 5, nil, 6, 7], a
927
- # end
928
- #
929
- # def test_rassoc
930
- # a1 = @cls[*%w( cat feline )]
931
- # a2 = @cls[*%w( dog canine )]
932
- # a3 = @cls[*%w( mule asinine )]
933
- # a = @cls[ a1, a2, a3 ]
934
- #
935
- # assert_equal(a1, a.rassoc('feline'))
936
- # assert_equal(a3, a.rassoc('asinine'))
937
- # assert_equal(nil, a.rassoc('dog'))
938
- # assert_equal(nil, a.rassoc('mule'))
939
- # assert_equal(nil, a.rassoc(1..2))
940
- # end
941
- #
942
- # # also delete_if
943
- # def test_reject!
944
- # a = @cls[ 1, 2, 3, 4, 5 ]
945
- # assert_equal(nil, a.reject! { false })
946
- # assert_equal(@cls[1, 2, 3, 4, 5], a)
947
- #
948
- # a = @cls[ 1, 2, 3, 4, 5 ]
949
- # assert_equal(a, a.reject! { true })
950
- # assert_equal(@cls[], a)
951
- #
952
- # a = @cls[ 1, 2, 3, 4, 5 ]
953
- # assert_equal(a, a.reject! { |i| i > 3 })
954
- # assert_equal(@cls[1, 2, 3], a)
955
- # end
956
- #
957
- # def test_replace
958
- # a = @cls[ 1, 2, 3]
959
- # a_id = a.__id__
960
- # assert_equal(@cls[4, 5, 6], a.replace(@cls[4, 5, 6]))
961
- # assert_equal(@cls[4, 5, 6], a)
962
- # assert_equal(a_id, a.__id__)
963
- # assert_equal(@cls[], a.replace(@cls[]))
964
- # end
965
- #
966
- # def test_reverse
967
- # a = @cls[*%w( dog cat bee ant )]
968
- # assert_equal(@cls[*%w(ant bee cat dog)], a.reverse)
969
- # assert_equal(@cls[*%w(dog cat bee ant)], a)
970
- # assert_equal(@cls[], @cls[].reverse)
971
- # end
972
- #
973
- # def test_reverse!
974
- # a = @cls[*%w( dog cat bee ant )]
975
- # assert_equal(@cls[*%w(ant bee cat dog)], a.reverse!)
976
- # assert_equal(@cls[*%w(ant bee cat dog)], a)
977
- # # Ruby 1.8 feature change:
978
- # # Array#reverse always returns self.
979
- # #assert_nil(@cls[].reverse!)
980
- # assert_equal @cls[], @cls[].reverse!
981
- # end
982
- #
983
- # def test_reverse_each
984
- # a = @cls[*%w( dog cat bee ant )]
985
- # i = a.length
986
- # a.reverse_each { |e|
987
- # i -= 1
988
- # assert_equal(a[i], e)
989
- # }
990
- # assert_equal(0, i)
991
- #
992
- # a = @cls[]
993
- # i = 0
994
- # a.reverse_each { |e|
995
- # assert(false, "Never get here")
996
- # }
997
- # assert_equal(0, i)
998
- # end
999
- #
1000
- # def test_rindex
1001
- # a = @cls[ 'cat', 99, /a/, 99, [ 1, 2, 3] ]
1002
- # assert_equal(0, a.rindex('cat'))
1003
- # assert_equal(3, a.rindex(99))
1004
- # assert_equal(4, a.rindex([1,2,3]))
1005
- # assert_nil(a.rindex('ca'))
1006
- # assert_nil(a.rindex([1,2]))
1007
- # end
1008
- #
1009
- # def test_shift
1010
- # a = @cls[ 'cat', 'dog' ]
1011
- # assert_equal('cat', a.shift)
1012
- # assert_equal(@cls['dog'], a)
1013
- # assert_equal('dog', a.shift)
1014
- # assert_equal(@cls[], a)
1015
- # assert_nil(a.shift)
1016
- # assert_equal(@cls[], a)
1017
- # end
1018
- #
1019
- def test_size
1020
- assert_equal(0, @cls[].size)
1021
- assert_equal(1, @cls[1].size)
1022
- assert_equal(100, @cls[*(0..99).to_a].size)
1023
- end
1024
- #
1025
- # def test_slice
1026
- # a = @cls[*(1..100).to_a]
1027
- #
1028
- # assert_equal(1, a.slice(0))
1029
- # assert_equal(100, a.slice(99))
1030
- # assert_nil(a.slice(100))
1031
- # assert_equal(100, a.slice(-1))
1032
- # assert_equal(99, a.slice(-2))
1033
- # assert_equal(1, a.slice(-100))
1034
- # assert_nil(a.slice(-101))
1035
- #
1036
- # assert_equal(@cls[1], a.slice(0,1))
1037
- # assert_equal(@cls[100], a.slice(99,1))
1038
- # assert_equal(@cls[], a.slice(100,1))
1039
- # assert_equal(@cls[100], a.slice(99,100))
1040
- # assert_equal(@cls[100], a.slice(-1,1))
1041
- # assert_equal(@cls[99], a.slice(-2,1))
1042
- #
1043
- # assert_equal(@cls[10, 11, 12], a.slice(9, 3))
1044
- # assert_equal(@cls[10, 11, 12], a.slice(-91, 3))
1045
- #
1046
- # assert_equal(@cls[1], a.slice(0..0))
1047
- # assert_equal(@cls[100], a.slice(99..99))
1048
- # assert_equal(@cls[], a.slice(100..100))
1049
- # assert_equal(@cls[100], a.slice(99..200))
1050
- # assert_equal(@cls[100], a.slice(-1..-1))
1051
- # assert_equal(@cls[99], a.slice(-2..-2))
1052
- #
1053
- # assert_equal(@cls[10, 11, 12], a.slice(9..11))
1054
- # assert_equal(@cls[10, 11, 12], a.slice(-91..-89))
1055
- #
1056
- # assert_nil(a.slice(10, -3))
1057
- # # Ruby 1.8 feature change:
1058
- # # Array#slice[size..x] always returns [].
1059
- # #assert_nil(a.slice(10..7))
1060
- # assert_equal @cls[], a.slice(10..7)
1061
- # end
1062
- #
1063
- # def test_slice!
1064
- # a = @cls[1, 2, 3, 4, 5]
1065
- # assert_equal(3, a.slice!(2))
1066
- # assert_equal(@cls[1, 2, 4, 5], a)
1067
- #
1068
- # a = @cls[1, 2, 3, 4, 5]
1069
- # assert_equal(4, a.slice!(-2))
1070
- # assert_equal(@cls[1, 2, 3, 5], a)
1071
- #
1072
- # a = @cls[1, 2, 3, 4, 5]
1073
- # assert_equal(@cls[3,4], a.slice!(2,2))
1074
- # assert_equal(@cls[1, 2, 5], a)
1075
- #
1076
- # a = @cls[1, 2, 3, 4, 5]
1077
- # assert_equal(@cls[4,5], a.slice!(-2,2))
1078
- # assert_equal(@cls[1, 2, 3], a)
1079
- #
1080
- # a = @cls[1, 2, 3, 4, 5]
1081
- # assert_equal(@cls[3,4], a.slice!(2..3))
1082
- # assert_equal(@cls[1, 2, 5], a)
1083
- #
1084
- # a = @cls[1, 2, 3, 4, 5]
1085
- # assert_equal(nil, a.slice!(20))
1086
- # assert_equal(@cls[1, 2, 3, 4, 5], a)
1087
- # end
1088
- #
1089
- # def test_sort
1090
- # a = @cls[ 4, 1, 2, 3 ]
1091
- # assert_equal(@cls[1, 2, 3, 4], a.sort)
1092
- # assert_equal(@cls[4, 1, 2, 3], a)
1093
- #
1094
- # assert_equal(@cls[4, 3, 2, 1], a.sort { |x, y| y <=> x} )
1095
- # assert_equal(@cls[4, 1, 2, 3], a)
1096
- #
1097
- # a.fill(1)
1098
- # assert_equal(@cls[1, 1, 1, 1], a.sort)
1099
- #
1100
- # assert_equal(@cls[], @cls[].sort)
1101
- # end
1102
- #
1103
- # def test_sort!
1104
- # a = @cls[ 4, 1, 2, 3 ]
1105
- # assert_equal(@cls[1, 2, 3, 4], a.sort!)
1106
- # assert_equal(@cls[1, 2, 3, 4], a)
1107
- #
1108
- # assert_equal(@cls[4, 3, 2, 1], a.sort! { |x, y| y <=> x} )
1109
- # assert_equal(@cls[4, 3, 2, 1], a)
1110
- #
1111
- # a.fill(1)
1112
- # assert_equal(@cls[1, 1, 1, 1], a.sort!)
1113
- #
1114
- # assert_equal(@cls[1], @cls[1].sort!)
1115
- # assert_equal(@cls[], @cls[].sort!)
1116
- # end
1117
-
1118
- def test_to_a
1119
- a = @cls[ 1, 2, 3 ]
1120
- a_id = a.__id__
1121
- assert_equal(a, a.to_a)
1122
- assert_equal(a_id, a.to_a.__id__)
1123
- end
1124
-
1125
- # def test_to_ary
1126
- # a = [ 1, 2, 3 ]
1127
- # b = @cls[*a]
1128
- #
1129
- # a_id = a.__id__
1130
- # assert_equal(a, b.to_ary)
1131
- # if (@cls == Array)
1132
- # assert_equal(a_id, a.to_ary.__id__)
1133
- # end
1134
- # end
1135
- #
1136
- # def test_to_s
1137
- # $, = ""
1138
- # a = @cls[]
1139
- # assert_equal("[]", a.to_s)
1140
- #
1141
- # $, = ""
1142
- # a = @cls[1, 2]
1143
- # assert_equal("[1, 2]", a.to_s)
1144
- #
1145
- # $, = ""
1146
- # a = @cls[1, 2, 3]
1147
- # assert_equal("[1, 2, 3]", a.to_s)
1148
- #
1149
- # $, = ":"
1150
- # a = @cls[1, 2, 3]
1151
- # assert_equal("[1, 2, 3]", a.to_s)
1152
- #
1153
- # $, = ""
1154
- # end
1155
- #
1156
- # def test_uniq
1157
- # a = @cls[ 1, 2, 3, 2, 1, 2, 3, 4, nil ]
1158
- # b = a.dup
1159
- # assert_equal(@cls[1, 2, 3, 4, nil], a.uniq)
1160
- # assert_equal(b, a)
1161
- #
1162
- # assert_equal(@cls[1, 2, 3], @cls[1, 2, 3].uniq)
1163
- # end
1164
- #
1165
- # def test_uniq!
1166
- # a = @cls[ 1, 2, 3, 2, 1, 2, 3, 4, nil ]
1167
- # assert_equal(@cls[1, 2, 3, 4, nil], a.uniq!)
1168
- # assert_equal(@cls[1, 2, 3, 4, nil], a)
1169
- #
1170
- # assert_nil(@cls[1, 2, 3].uniq!)
1171
- # end
1172
- #
1173
- # def test_unshift
1174
- # a = @cls[]
1175
- # assert_equal(@cls['cat'], a.unshift('cat'))
1176
- # assert_equal(@cls['dog', 'cat'], a.unshift('dog'))
1177
- # assert_equal(@cls[nil, 'dog', 'cat'], a.unshift(nil))
1178
- # assert_equal(@cls[@cls[1,2], nil, 'dog', 'cat'], a.unshift(@cls[1, 2]))
1179
- # end
1180
- #
1181
- # def test_OR # '|'
1182
- # assert_equal(@cls[], @cls[] | @cls[])
1183
- # assert_equal(@cls[1], @cls[1] | @cls[])
1184
- # assert_equal(@cls[1], @cls[] | @cls[1])
1185
- # assert_equal(@cls[1], @cls[1] | @cls[1])
1186
- #
1187
- # assert_equal(@cls[1,2], @cls[1] | @cls[2])
1188
- # assert_equal(@cls[1,2], @cls[1, 1] | @cls[2, 2])
1189
- # assert_equal(@cls[1,2], @cls[1, 2] | @cls[1, 2])
1190
- # end
1191
-
1192
- end