diff options
Diffstat (limited to 'test/ruby/test_array.rb')
| -rw-r--r-- | test/ruby/test_array.rb | 187 |
1 files changed, 4 insertions, 183 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index f58f8a2778..30bf13795c 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -652,8 +652,8 @@ class TestArray < Test::Unit::TestCase b.concat(b, b) assert_equal([4, 5, 4, 5, 4, 5], b) - assert_raise(TypeError) { @cls[0].concat(:foo) } - assert_raise(FrozenError) { @cls[0].freeze.concat(:foo) } + assert_raise(TypeError) { [0].concat(:foo) } + assert_raise(FrozenError) { [0].freeze.concat(:foo) } a = @cls[nil] def (x = Object.new).to_ary @@ -1109,19 +1109,6 @@ class TestArray < Test::Unit::TestCase assert_not_include(a, [1,2]) end - def test_intersect? - a = @cls[ 1, 2, 3] - assert_send([a, :intersect?, [3]]) - assert_not_send([a, :intersect?, [4]]) - assert_not_send([a, :intersect?, []]) - end - - def test_intersect_big_array - assert_send([@cls[ 1, 4, 5 ]*64, :intersect?, @cls[ 1, 2, 3 ]*64]) - assert_not_send([@cls[ 1, 2, 3 ]*64, :intersect?, @cls[ 4, 5, 6 ]*64]) - assert_not_send([@cls[], :intersect?, @cls[ 1, 2, 3 ]*64]) - end - def test_index a = @cls[ 'cat', 99, /a/, 99, @cls[ 1, 2, 3] ] assert_equal(0, a.index('cat')) @@ -1294,12 +1281,6 @@ class TestArray < Test::Unit::TestCase =end end - def test_pack_with_buffer - n = [ 65, 66, 67 ] - str = "a" * 100 - assert_equal("aaaABC", n.pack("@3ccc", buffer: str.dup), "[Bug #19116]") - end - def test_pop a = @cls[ 'cat', 'dog' ] assert_equal('dog', a.pop) @@ -1445,14 +1426,6 @@ class TestArray < Test::Unit::TestCase assert_raise(FrozenError) { fa.replace(42) } end - def test_replace_wb_variable_width_alloc - small_embed = [] - 4.times { GC.start } # age small_embed - large_embed = [1, 2, 3, 4, 5, Array.new] # new young object - small_embed.replace(large_embed) # adds old to young reference - GC.verify_internal_consistency - end - def test_reverse a = @cls[*%w( dog cat bee ant )] assert_equal(@cls[*%w(ant bee cat dog)], a.reverse) @@ -1586,96 +1559,6 @@ class TestArray < Test::Unit::TestCase assert_equal_instance(a.values_at(*idx), a.slice((3..90)%2)) idx = 90.step(3, -2).to_a assert_equal_instance(a.values_at(*idx), a.slice((90 .. 3)% -2)) - - a = [0, 1, 2, 3, 4, 5] - assert_equal([2, 1, 0], a.slice((2..).step(-1))) - assert_equal([2, 0], a.slice((2..).step(-2))) - assert_equal([2], a.slice((2..).step(-3))) - assert_equal([2], a.slice((2..).step(-4))) - - assert_equal([3, 2, 1, 0], a.slice((-3..).step(-1))) - assert_equal([3, 1], a.slice((-3..).step(-2))) - assert_equal([3, 0], a.slice((-3..).step(-3))) - assert_equal([3], a.slice((-3..).step(-4))) - assert_equal([3], a.slice((-3..).step(-5))) - - assert_equal([5, 4, 3, 2, 1, 0], a.slice((..0).step(-1))) - assert_equal([5, 3, 1], a.slice((..0).step(-2))) - assert_equal([5, 2], a.slice((..0).step(-3))) - assert_equal([5, 1], a.slice((..0).step(-4))) - assert_equal([5, 0], a.slice((..0).step(-5))) - assert_equal([5], a.slice((..0).step(-6))) - assert_equal([5], a.slice((..0).step(-7))) - - assert_equal([5, 4, 3, 2, 1], a.slice((...0).step(-1))) - assert_equal([5, 3, 1], a.slice((...0).step(-2))) - assert_equal([5, 2], a.slice((...0).step(-3))) - assert_equal([5, 1], a.slice((...0).step(-4))) - assert_equal([5], a.slice((...0).step(-5))) - assert_equal([5], a.slice((...0).step(-6))) - - assert_equal([5, 4, 3, 2], a.slice((...1).step(-1))) - assert_equal([5, 3], a.slice((...1).step(-2))) - assert_equal([5, 2], a.slice((...1).step(-3))) - assert_equal([5], a.slice((...1).step(-4))) - assert_equal([5], a.slice((...1).step(-5))) - - assert_equal([5, 4, 3, 2, 1], a.slice((..-5).step(-1))) - assert_equal([5, 3, 1], a.slice((..-5).step(-2))) - assert_equal([5, 2], a.slice((..-5).step(-3))) - assert_equal([5, 1], a.slice((..-5).step(-4))) - assert_equal([5], a.slice((..-5).step(-5))) - assert_equal([5], a.slice((..-5).step(-6))) - - assert_equal([5, 4, 3, 2], a.slice((...-5).step(-1))) - assert_equal([5, 3], a.slice((...-5).step(-2))) - assert_equal([5, 2], a.slice((...-5).step(-3))) - assert_equal([5], a.slice((...-5).step(-4))) - assert_equal([5], a.slice((...-5).step(-5))) - - assert_equal([4, 3, 2, 1], a.slice((4..1).step(-1))) - assert_equal([4, 2], a.slice((4..1).step(-2))) - assert_equal([4, 1], a.slice((4..1).step(-3))) - assert_equal([4], a.slice((4..1).step(-4))) - assert_equal([4], a.slice((4..1).step(-5))) - - assert_equal([4, 3, 2], a.slice((4...1).step(-1))) - assert_equal([4, 2], a.slice((4...1).step(-2))) - assert_equal([4], a.slice((4...1).step(-3))) - assert_equal([4], a.slice((4...1).step(-4))) - - assert_equal([4, 3, 2, 1], a.slice((-2..1).step(-1))) - assert_equal([4, 2], a.slice((-2..1).step(-2))) - assert_equal([4, 1], a.slice((-2..1).step(-3))) - assert_equal([4], a.slice((-2..1).step(-4))) - assert_equal([4], a.slice((-2..1).step(-5))) - - assert_equal([4, 3, 2], a.slice((-2...1).step(-1))) - assert_equal([4, 2], a.slice((-2...1).step(-2))) - assert_equal([4], a.slice((-2...1).step(-3))) - assert_equal([4], a.slice((-2...1).step(-4))) - - assert_equal([4, 3, 2, 1], a.slice((4..-5).step(-1))) - assert_equal([4, 2], a.slice((4..-5).step(-2))) - assert_equal([4, 1], a.slice((4..-5).step(-3))) - assert_equal([4], a.slice((4..-5).step(-4))) - assert_equal([4], a.slice((4..-5).step(-5))) - - assert_equal([4, 3, 2], a.slice((4...-5).step(-1))) - assert_equal([4, 2], a.slice((4...-5).step(-2))) - assert_equal([4], a.slice((4...-5).step(-3))) - assert_equal([4], a.slice((4...-5).step(-4))) - - assert_equal([4, 3, 2, 1], a.slice((-2..-5).step(-1))) - assert_equal([4, 2], a.slice((-2..-5).step(-2))) - assert_equal([4, 1], a.slice((-2..-5).step(-3))) - assert_equal([4], a.slice((-2..-5).step(-4))) - assert_equal([4], a.slice((-2..-5).step(-5))) - - assert_equal([4, 3, 2], a.slice((-2...-5).step(-1))) - assert_equal([4, 2], a.slice((-2...-5).step(-2))) - assert_equal([4], a.slice((-2...-5).step(-3))) - assert_equal([4], a.slice((-2...-5).step(-4))) end def test_slice_out_of_range @@ -1793,37 +1676,6 @@ class TestArray < Test::Unit::TestCase assert_equal([1, 2, 3, 4], a) end - def test_freeze_inside_sort! - array = [1, 2, 3, 4, 5] - frozen_array = nil - assert_raise(FrozenError) do - count = 0 - array.sort! do |a, b| - array.freeze if (count += 1) == 6 - frozen_array ||= array.map.to_a if array.frozen? - b <=> a - end - end - assert_equal(frozen_array, array) - - object = Object.new - array = [1, 2, 3, 4, 5] - object.define_singleton_method(:>){|_| array.freeze; true} - assert_raise(FrozenError) do - array.sort! do |a, b| - object - end - end - - object = Object.new - array = [object, object] - object.define_singleton_method(:>){|_| array.freeze; true} - object.define_singleton_method(:<=>){|o| object} - assert_raise(FrozenError) do - array.sort! - end - end - def test_sort_with_callcc need_continuation n = 1000 @@ -2896,17 +2748,6 @@ class TestArray < Test::Unit::TestCase assert_equal [[42, 1]], [42].zip(r), bug8153 end - def test_zip_with_enumerator - bug17814 = "ruby-core:103513" - - step = 0.step - e = Enumerator.produce { step.next } - a = %w(a b c) - assert_equal([["a", 0], ["b", 1], ["c", 2]], a.zip(e), bug17814) - assert_equal([["a", 3], ["b", 4], ["c", 5]], a.zip(e), bug17814) - assert_equal([["a", 6], ["b", 7], ["c", 8]], a.zip(e), bug17814) - end - def test_transpose assert_equal([[1, :a], [2, :b], [3, :c]], [[1, 2, 3], [:a, :b, :c]].transpose) @@ -2986,9 +2827,7 @@ class TestArray < Test::Unit::TestCase assert_raise(RangeError) { [*0..2].shuffle(random: gen) } - end - def test_shuffle_random_clobbering ary = (0...10000).to_a gen = proc do ary.replace([]) @@ -2998,9 +2837,7 @@ class TestArray < Test::Unit::TestCase alias rand call end assert_raise(RuntimeError) {ary.shuffle!(random: gen)} - end - def test_shuffle_random_zero zero = Object.new def zero.to_int 0 @@ -3013,10 +2850,7 @@ class TestArray < Test::Unit::TestCase end ary = (0...10000).to_a assert_equal(ary.rotate, ary.shuffle(random: gen_to_int)) - end - def test_shuffle_random_invalid_generator - ary = (0...10).to_a assert_raise(NoMethodError) { ary.shuffle(random: Object.new) } @@ -3033,9 +2867,7 @@ class TestArray < Test::Unit::TestCase assert_include([0, 1, 2], sample) } end - end - def test_sample_statistics srand(0) a = (1..18).to_a (0..20).each do |n| @@ -3052,13 +2884,9 @@ class TestArray < Test::Unit::TestCase end assert_operator(h.values.min * 2, :>=, h.values.max) if n != 0 end - end - def test_sample_invalid_argument assert_raise(ArgumentError, '[ruby-core:23374]') {[1, 2].sample(-1)} - end - def test_sample_random_srand0 gen = Random.new(0) srand(0) a = (1..18).to_a @@ -3067,15 +2895,13 @@ class TestArray < Test::Unit::TestCase assert_equal(a.sample(n), a.sample(n, random: gen), "#{i}/#{n}") end end - end - def test_sample_unknown_keyword assert_raise_with_message(ArgumentError, /unknown keyword/) do [0, 1, 2].sample(xawqij: "a") end end - def test_sample_random_generator + def test_sample_random ary = (0...10000).to_a assert_raise(ArgumentError) {ary.sample(1, 2, random: nil)} gen0 = proc do |max| @@ -3118,9 +2944,7 @@ class TestArray < Test::Unit::TestCase assert_equal([5000, 0, 5001, 2, 5002, 4, 5003, 6, 5004, 8, 5005], ary.sample(11, random: gen0)) ary.sample(11, random: gen1) # implementation detail, may change in the future assert_equal([], ary) - end - def test_sample_random_generator_half half = Object.new def half.to_int 5000 @@ -3133,10 +2957,7 @@ class TestArray < Test::Unit::TestCase end ary = (0...10000).to_a assert_equal(5000, ary.sample(random: gen_to_int)) - end - def test_sample_random_invalid_generator - ary = (0..10).to_a assert_raise(NoMethodError) { ary.sample(random: Object.new) } @@ -3394,7 +3215,7 @@ class TestArray < Test::Unit::TestCase end EOS rescue Timeout::Error => e - omit e.message + skip e.message end end |
