summaryrefslogtreecommitdiff
path: root/test/ruby/test_array.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_array.rb')
-rw-r--r--test/ruby/test_array.rb143
1 files changed, 4 insertions, 139 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index 97e2fa3de8..0ed8ada95c 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -529,19 +529,14 @@ class TestArray < Test::Unit::TestCase
end
def test_assoc
- def (a4 = Object.new).to_ary
- %w( pork porcine )
- end
-
a1 = @cls[*%w( cat feline )]
a2 = @cls[*%w( dog canine )]
a3 = @cls[*%w( mule asinine )]
- a = @cls[ a1, a2, a3, a4 ]
+ a = @cls[ a1, a2, a3 ]
assert_equal(a1, a.assoc('cat'))
assert_equal(a3, a.assoc('mule'))
- assert_equal(%w( pork porcine ), a.assoc("pork"))
assert_equal(nil, a.assoc('asinine'))
assert_equal(nil, a.assoc('wombat'))
assert_equal(nil, a.assoc(1..2))
@@ -1334,17 +1329,13 @@ class TestArray < Test::Unit::TestCase
end
def test_rassoc
- def (a4 = Object.new).to_ary
- %w( pork porcine )
- end
a1 = @cls[*%w( cat feline )]
a2 = @cls[*%w( dog canine )]
a3 = @cls[*%w( mule asinine )]
- a = @cls[ a1, a2, a3, a4 ]
+ a = @cls[ a1, a2, a3 ]
assert_equal(a1, a.rassoc('feline'))
assert_equal(a3, a.rassoc('asinine'))
- assert_equal(%w( pork porcine ), a.rassoc("porcine"))
assert_equal(nil, a.rassoc('dog'))
assert_equal(nil, a.rassoc('mule'))
assert_equal(nil, a.rassoc(1..2))
@@ -1454,14 +1445,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)
@@ -1595,96 +1578,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
@@ -1702,14 +1595,6 @@ class TestArray < Test::Unit::TestCase
assert_equal([100], a.slice(-1, 1_000_000_000))
end
- def test_slice_gc_compact_stress
- EnvUtil.under_gc_compact_stress { assert_equal([1, 2, 3, 4, 5], (0..10).to_a[1, 5]) }
- EnvUtil.under_gc_compact_stress do
- a = [0, 1, 2, 3, 4, 5]
- assert_equal([2, 1, 0], a.slice((2..).step(-1)))
- end
- end
-
def test_slice!
a = @cls[1, 2, 3, 4, 5]
assert_equal(3, a.slice!(2))
@@ -3003,9 +2888,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([])
@@ -3015,9 +2898,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
@@ -3030,10 +2911,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)
}
@@ -3050,9 +2928,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|
@@ -3069,13 +2945,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
@@ -3084,15 +2956,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|
@@ -3135,9 +3005,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
@@ -3150,10 +3018,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)
}
@@ -3415,7 +3280,7 @@ class TestArray < Test::Unit::TestCase
end
EOS
rescue Timeout::Error => e
- omit e.message
+ skip e.message
end
end