Commit 9fe821c2
9fe821c2c615Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 10 files · ~2 modified · -8 deleted
Description
test: collapse 5 range_* tests into one range.rb
Range methods coverage. Was five separate tests covering the
basic surface, cover?/min/max/count, Range#map, inclusive-vs-
exclusive (slicing / for-in / case-when), and step without block
param. No class collisions; the only top-level def (classify
in the inclusive/exclusive section) is unique. Local names use
per-section prefixes where the original tests reused generic
names like r, sum, i.
5 .rb (counting the existing range.rb) → 1. ~5s saved on Windows test step at the ~1.2s/test rate.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 9fe821c2c615
- Parent
- 9dcaf5fbd5ea
test/range.rbmodifiedView file
r = (1..10)puts r.first # 1puts r.last # 10puts r.include?(5) # trueputs r.include?(11) # false# Range methods — first / last / include? / to_a / each, cover? /# min / max / count, Range#map, inclusive-vs-exclusive distinction,# step without block param. Was five separate tests; merged here.# No class collisions. The only top-level def (`classify` in the# inclusive/exclusive section) is unique within the file. Local# names use per-section prefixes where the original tests reused# generic names like `r`, `sum`, `i`.arr = r.to_aputs arr.length # 10puts arr.sum # 55# === Basic Range methods ===r0 = (1..10)puts r0.first # 1puts r0.last # 10puts r0.include?(5) # trueputs r0.include?(11) # falsearr0 = r0.to_aputs arr0.length # 10puts arr0.sum # 55total = 0r.each do |i| total += ir0.each do |x| total += xendputs total # 55puts total # 55puts "done"# === cover? / min / max / count ===puts (1..10).cover?(5)puts (1..10).cover?(1)puts (1..10).cover?(10)puts (1..10).cover?(0)puts (1..10).cover?(11)puts (-5..5).cover?(0)puts (-5..5).cover?(-5)puts (-5..5).cover?(6)puts (1..10).minputs (1..10).maxputs (-5..5).minputs (-5..5).maxputs (100..200).minputs (100..200).maxputs (1..10).countputs (1..1).countputs (-5..5).countputs (100..200).countputs (1...10).countputs (1...1).countputs (-5...5).count# === Range#map ===puts (0..3).map { |i| i * 10 }.length # 4puts (0..3).map { |i| i * 10 }[2] # 20puts (0...3).map { |i| i }.length # 3puts (0...3).map { |i| i }[2] # 2puts ((1..3).map { |i| "x#{i}" }.join(",")) # x1,x2,x3puts ((0...3).map { |i| i * 0.5 }.length) # 3# === Inclusive vs exclusive (slicing / for-in / Range#to_a / case-when) ===ia = [10, 20, 30, 40, 50]puts ia[1..3].length # 3 (inclusive)puts ia[1...3].length # 2 (exclusive)puts ia[1...3][0] # 20puts ia[1...3][1] # 30sa = "a,b,c,d,e".split(",")puts sa[0..2].join(":") # a:b:cputs sa[0...2].join(":") # a:bfa = [1.5, 2.5, 3.5, 4.5]puts fa[0..2].length # 3puts fa[0...2].length # 2puts fa[0...3].sum # 7.5s = "abcdef"puts s[1..3] # bcdputs s[1...3] # bcsum_inc = 0for ix in 1..3 sum_inc = sum_inc + ixendputs sum_inc # 6sum_exc = 0for ix in 1...3 sum_exc = sum_exc + ixendputs sum_exc # 3puts (1..3).to_a.length # 3puts (1...3).to_a.length # 2def classify(n) case n when 0...10 then "small" when 10..99 then "medium" else "large" endendputs classify(5)puts classify(9)puts classify(10)puts classify(99)puts classify(100)# === step without block param ===# `Integer#step` with a do-block that omits its parameter used a# synthesized `_i` index that wasn't declared. Two paramless `step`# blocks in the same function also redefined it.sum_step = 01.step(10, 1) do sum_step += 1end1.step(5, 1) do sum_step += 10end1.step(5, 1) do sum_step += 100endputs sum_steptest/range.rb.expectedmodifiedView file
Loading diff…
test/range_completeness.rbdeleted
Loading diff…
test/range_completeness.rb.expecteddeleted
Loading diff…
test/range_exclusive.rbdeleted
Loading diff…
test/range_exclusive.rb.expecteddeleted
Loading diff…
test/range_map.rbdeleted
Loading diff…
test/range_map.rb.expecteddeleted
Loading diff…
test/range_step_no_block_param.rbdeleted
Loading diff…
test/range_step_no_block_param.rb.expecteddeleted
Loading diff…