Skip to content

Commit 58ae5ea

Browse files
sampokuokkanennobu
authored andcommitted
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
1 parent 18ae8d6 commit 58ae5ea

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

test/ruby/test_array.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,19 +1846,21 @@ def test_sort!
18461846
assert_equal([1, 2, 3, 4], a)
18471847
end
18481848

1849-
def test_freeze_inside_sort!
1849+
def test_freeze_inside_sort_bang
18501850
array = [1, 2, 3, 4, 5]
18511851
frozen_array = nil
18521852
assert_raise(FrozenError) do
18531853
count = 0
18541854
array.sort! do |a, b|
1855-
array.freeze if (count += 1) == 6
1855+
array.freeze if (count += 1) == 3
18561856
frozen_array ||= array.map.to_a if array.frozen?
18571857
b <=> a
18581858
end
18591859
end
18601860
assert_equal(frozen_array, array)
1861+
end
18611862

1863+
def test_freeze_inside_sort_bang_non_numeric_block
18621864
object = Object.new
18631865
array = [1, 2, 3, 4, 5]
18641866
object.define_singleton_method(:>){|_| array.freeze; true}
@@ -1867,7 +1869,9 @@ def test_freeze_inside_sort!
18671869
object
18681870
end
18691871
end
1872+
end
18701873

1874+
def test_freeze_inside_sort_bang_non_numeric_no_block
18711875
object = Object.new
18721876
array = [object, object]
18731877
object.define_singleton_method(:>){|_| array.freeze; true}

0 commit comments

Comments
 (0)