Commit 4c3d2e30
4c3d2e30a19eMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 12 files · +2 added · -10 deleted
Description
test: collapse 5 float_* tests into one float.rb
FloatArray reductions (min/max/sum/first/last), FloatArray slicing
(range, start+len, negative, clamped), FloatArray#shift, Float#ceil
/floor/round/truncate with precision arg, and Float#to_s byte-
identical output. Five tests; merged. No class collisions; locals
reused across the originals (f, arr, a) get per-section
prefixes (fr_, fs_, fsh_).
5 .rb → 1. ~6s saved on Windows test step at the ~1.2s/test rate.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 4c3d2e30a19e
- Parent
- 07d622b3b225
test/float.rbaddedView file
# Float and FloatArray coverage — to_s formatting, FloatArray# reductions / slicing / shift, and Float#ceil/floor/round/truncate# with a precision arg. Was five separate tests; merged. No class# collisions; locals reused across the originals (`f`, `arr`, `a`)# get per-section prefixes so spinel's local-type inference doesn't# unify them.# === FloatArray reductions: min / max / sum / first / last ===fr_arr = [1.5, 2.5, 0.5, 3.5]puts fr_arr.min # 0.5puts fr_arr.max # 3.5puts fr_arr.first # 1.5puts fr_arr.last # 3.5fr_neg = [-1.5, -3.25, 2.75]puts fr_neg.min # -3.25puts fr_neg.max # 2.75fr_one = [4.5]puts fr_one.min # 4.5puts fr_one.max # 4.5# Sum with non-integer-valued result (avoids the stale-type truncation# that would print "4" instead of "4.5").fr_sum = [1.5, 2.5, 0.5]puts fr_sum.sum # 4.5# === FloatArray slicing: a[range] and a[start, len] ===fs_a = [1.5, 2.5, 3.5, 4.5, 5.5]fs_b = fs_a[1..3]puts fs_b.length # 3puts fs_b[0] # 2.5puts fs_b[1] # 3.5puts fs_b[2] # 4.5fs_c = fs_a[1, 2]puts fs_c.length # 2puts fs_c[0] # 2.5puts fs_c[1] # 3.5fs_d = fs_a[-2, 2]puts fs_d.length # 2puts fs_d[0] # 4.5puts fs_d[1] # 5.5fs_e = fs_a[2, 100]puts fs_e.length # 3 (clamped)puts fs_e[0] # 3.5puts fs_e[2] # 5.5puts fs_a[0] # 1.5puts fs_a[-1] # 5.5puts fs_a[1..3].sum # 10.5# === FloatArray#shift ===fsh_arr = [1.5, 2.5, 3.5, 4.5]puts fsh_arr.shift # 1.5puts fsh_arr.length # 3puts fsh_arr[0] # 2.5while fsh_arr.length > 0 puts fsh_arr.shiftendputs fsh_arr.length # 0# === Float#ceil/floor/round/truncate with precision arg ===puts 3.14159.round(2)puts 3.14159.round(4)puts 1.5.round(1)puts 2.5.round(1)puts 3.14159.ceil(2)puts 3.14159.ceil(4)puts 1.001.ceil(2)puts 3.14159.floor(2)puts 3.14159.floor(4)puts 1.999.floor(2)puts 3.14159.truncate(2)puts 3.14159.truncate(4)puts (-1.567).truncate(2)puts 3.14.roundputs 3.14.ceilputs 3.14.floorputs 3.14.truncate# Negative precision: bool-compare for type-stable output across# CRuby's Integer-return rule vs. Spinel's uniform Float inference.puts 12345.6789.floor(-2) == 12300puts 12345.6789.ceil(-2) == 12400puts 12345.6789.round(-1) == 12350puts 12345.6789.truncate(-2) == 12300puts (-12345.6789).floor(-2) == -12400puts (-12345.6789).ceil(-2) == -12300# === Float#to_s / p / puts byte-identical output ===# Shortest decimal that round-trips; fixed-point inside CRuby's# [-4, 15] decimal-exponent window, scientific (`d.ddde+NN`)# outside.puts 1.0puts 100.0puts(-3.25)puts 1234567890.0puts 1234567890.5puts 0.1puts 0.3puts 0.30000000000000004puts 0.0001puts 0.00001puts 1.5e14puts 1.0e15puts 9.99e15puts 1.0e16puts 1.0e100puts(-0.0)puts Float::INFINITYputs(-Float::INFINITY)puts Float::NANp 1.0p 1234567890.5p 1.0e16p(-0.0)test/float.rb.expectedaddedView file
Loading diff…
test/float_array.rbdeleted
Loading diff…
test/float_array.rb.expecteddeleted
Loading diff…
test/float_array_range.rbdeleted
Loading diff…
test/float_array_range.rb.expecteddeleted
Loading diff…
test/float_array_shift.rbdeleted
Loading diff…
test/float_array_shift.rb.expecteddeleted
Loading diff…
test/float_precision_args.rbdeleted
Loading diff…
test/float_precision_args.rb.expecteddeleted
Loading diff…
test/float_to_s.rbdeleted
Loading diff…
test/float_to_s.rb.expecteddeleted
Loading diff…