mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 21:14:23 +02:00
* array.c (rb_ary_resize): new utility function. [ruby-dev:42912]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30465 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
697a45b196
commit
c8aaf31fdd
5 changed files with 90 additions and 0 deletions
29
test/-ext-/array/test_resize.rb
Normal file
29
test/-ext-/array/test_resize.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'test/unit'
|
||||
require '-test-/array/resize'
|
||||
|
||||
class TestArray < Test::Unit::TestCase
|
||||
class TestResize < Test::Unit::TestCase
|
||||
def test_expand
|
||||
feature = '[ruby-dev:42912]'
|
||||
ary = [*1..10]
|
||||
ary.resize(10)
|
||||
assert_equal(10, ary.size, feature)
|
||||
assert_equal([*1..10], ary, feature)
|
||||
ary.resize(100)
|
||||
assert_equal(100, ary.size, feature)
|
||||
assert_equal([*1..10]+[nil]*90, ary, feature)
|
||||
ary.resize(20)
|
||||
assert_equal(20, ary.size, feature)
|
||||
assert_equal([*1..10]+[nil]*10, ary, feature)
|
||||
ary.resize(2)
|
||||
assert_equal(2, ary.size, feature)
|
||||
assert_equal([1,2], ary, feature)
|
||||
ary.resize(3)
|
||||
assert_equal(3, ary.size, feature)
|
||||
assert_equal([1,2,nil], ary, feature)
|
||||
ary.resize(10)
|
||||
assert_equal(10, ary.size, feature)
|
||||
assert_equal([1,2]+[nil]*8, ary, feature)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue