diff options
| author | Sampo Kuokkanen <sampo.kuokkanen@gmail.com> | 2026-05-07 19:00:48 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu.nakada@gmail.com> | 2026-05-07 20:59:12 +0900 |
| commit | 58ae5ea7ee00c2f31a678574a7ccab28716cb4d0 (patch) | |
| tree | 1194c9ddd454bb19351ecec8241f43ac5693d033 | |
| parent | 18ae8d6deda99d9f5bf5d372c27a72f95d1f7948 (diff) | |
Split test_freeze_inside_sort! and reduce comparator count
The first sub-test froze on the 6th comparator call. CRuby's insertion sort makes 10 comparisons reversing [1,2,3,4,5], but TimSort detects the descending run in 4 and never reaches 6 and the freeze line silently does nothing.
Separately, three independent paths (block + numeric, block + non-numeric, no-block + non-numeric) were bundled into one method even though the test had independent setup. Split into:
test_freeze_inside_sort_bang
test_freeze_inside_sort_bang_non_numeric_block
test_freeze_inside_sort_bang_non_numeric_no_block
| -rw-r--r-- | test/ruby/test_array.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 04e15b6d87..cad9bf5cc8 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -1846,19 +1846,21 @@ class TestArray < Test::Unit::TestCase assert_equal([1, 2, 3, 4], a) end - def test_freeze_inside_sort! + def test_freeze_inside_sort_bang 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 + array.freeze if (count += 1) == 3 frozen_array ||= array.map.to_a if array.frozen? b <=> a end end assert_equal(frozen_array, array) + end + def test_freeze_inside_sort_bang_non_numeric_block object = Object.new array = [1, 2, 3, 4, 5] object.define_singleton_method(:>){|_| array.freeze; true} @@ -1867,7 +1869,9 @@ class TestArray < Test::Unit::TestCase object end end + end + def test_freeze_inside_sort_bang_non_numeric_no_block object = Object.new array = [object, object] object.define_singleton_method(:>){|_| array.freeze; true} |
