diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-03-29 20:59:08 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-03-29 20:59:08 +0900 |
| commit | 8cdac8221dafbf23fca898afb4249e5fc0a163c6 (patch) | |
| tree | 73a64e4ff39604a63dcf442fb10a2a26f13831a8 /mrbgems/mruby-array-ext/test/array.rb | |
| parent | a88403cc85ce9fc8a8816128fde63b1676960f07 (diff) | |
| parent | aa4a18e81ec9005965eeb1dcf10c5571dc41719a (diff) | |
| download | mruby-8cdac8221dafbf23fca898afb4249e5fc0a163c6.tar.gz mruby-8cdac8221dafbf23fca898afb4249e5fc0a163c6.zip | |
Merge pull request #1978 from suzukaze/add-array.fill
Add Array#fill
Diffstat (limited to 'mrbgems/mruby-array-ext/test/array.rb')
| -rw-r--r-- | mrbgems/mruby-array-ext/test/array.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/mrbgems/mruby-array-ext/test/array.rb b/mrbgems/mruby-array-ext/test/array.rb index ab830cca7..7f296f591 100644 --- a/mrbgems/mruby-array-ext/test/array.rb +++ b/mrbgems/mruby-array-ext/test/array.rb @@ -118,3 +118,16 @@ assert("Array#fetch") do assert_equal 100, ret assert_raise(IndexError) { a.fetch(100) } end + +assert("Array#fill") do + a = [ "a", "b", "c", "d" ] + assert_equal ["x", "x", "x", "x"], a.fill("x") + assert_equal ["x", "x", "x", "w"], a.fill("w", -1) + assert_equal ["x", "x", "z", "z"], a.fill("z", 2, 2) + assert_equal ["y", "y", "z", "z"], a.fill("y", 0..1) + assert_equal [0, 1, 4, 9], a.fill { |i| i*i } + assert_equal [0, 1, 8, 27], a.fill(-2) { |i| i*i*i } + assert_equal [0, 2, 3, 27], a.fill(1, 2) { |i| i+1 } + assert_equal [1, 2, 3, 27], a.fill(0..1) { |i| i+1 } + assert_raise(ArgumentError) { a.fill } +end |
