Commit 8b20804e

8b20804e40efMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 18 files · +2 added · -16 deleted

Description

test: bundle 8 more standalone tests into bundle_misc_c_36

Fold float_array_sort, integer_literal_large, program_name_gvar, multi_write_as_expression, range_predicate_block, fetch_nil_default_distinguishes_zero, stdlib, math_fn_parity into a single bundled file. Each test wrapped in def t_<name>; ...; end so its locals stay scoped. Same pattern as bundle_misc_c_35.

Tests: default 448/0/0 (was 455, -8 standalone + the bundle already counted as 1).

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
8b20804e40ef
Parent
21a950efea35

test/bundle_misc_c_36.rbaddedView file

1+# Bundled tests:
2+# - float_array_sort
3+# - integer_literal_large
4+# - program_name_gvar
5+# - multi_write_as_expression
6+# - range_predicate_block
7+# - fetch_nil_default_distinguishes_zero
8+# - stdlib
9+# - math_fn_parity
10+
11+# === float_array_sort ===
12+def t_float_array_sort
13+ a = [3.5, 1.25, 2.0, 0.75, 4.125]
14+ b = a.sort
15+ puts b.length
16+
17+ i = 0
18+ while i < b.length
19+ puts b[i]
20+ i = i + 1
21+ end
22+
23+ # Source unchanged.
24+ puts a[0]
25+ puts a[1]
26+end
27+t_float_array_sort
28+
29+# === integer_literal_large ===
30+def t_integer_literal_large
31+ mod = 4_294_967_296
32+ puts mod
33+ puts 16_777_621 % mod
34+
35+ hash = 2_166_136_261
36+ data = "spinel"
37+ i = 0
38+ while i < data.length
39+ hash = (hash * 16_777_619 + data.getbyte(i)) % mod
40+ i += 1
41+ end
42+
43+ puts hash
44+end
45+t_integer_literal_large
46+
47+# === program_name_gvar ===
48+def t_program_name_gvar
49+ # `$PROGRAM_NAME` / `$0` are Ruby's standard aliases.
50+ puts $PROGRAM_NAME.length > 0
51+ puts $0.length > 0
52+end
53+t_program_name_gvar
54+
55+# === multi_write_as_expression ===
56+def t_multi_write_as_expression
57+ # #554. `(a, b = 10, 11)` used as an expression returns the RHS array.
58+ p( (a, b = 10, 11)[1] )
59+ p a
60+ p b
61+
62+ arr = (x, y = "hi", "lo")
63+ p arr[0]
64+ p arr[1]
65+ p x
66+ p y
67+end
68+t_multi_write_as_expression
69+
70+# === range_predicate_block ===
71+def t_range_predicate_block
72+ # (a..b).any?/all?/none?/one? { |i| ... }
73+ puts (0..5).all? {|i| i >= 0 } # true
74+ puts (0..5).all? {|i| i < 3 } # false
75+ puts (0..3).all? {|i| (0..3).cover?(i) } # true
76+
77+ puts (0..5).any? {|i| i == 3 } # true
78+ puts (0..5).any? {|i| i > 100 } # false
79+
80+ puts (0..5).none? {|i| i > 100 } # true
81+ puts (0..5).none? {|i| i == 3 } # false
82+
83+ puts (0..5).one? {|i| i == 3 } # true
84+ puts (0..5).one? {|i| i >= 4 } # false
85+ puts (0..5).one? {|i| i > 100 } # false
86+end
87+t_range_predicate_block
88+
89+# === fetch_nil_default_distinguishes_zero ===
90+def t_fetch_nil_default_distinguishes_zero
91+ # #682: hash.fetch(k, nil).nil? distinguishes missing-key from a 0 value.
92+ h0 = {k: 0}
93+ v0 = h0.fetch(:k, nil)
94+ puts v0.nil? ? "missing" : "found-0"
95+
96+ hm = {}
97+ vm = hm.fetch(:k, nil)
98+ puts vm.nil? ? "missing" : "found-m"
99+
100+ h1 = {k: 42}
101+ v1 = h1.fetch(:k, nil)
102+ puts v1.nil? ? "missing" : "found-#{v1}"
103+
104+ hs = {"a" => 0}
105+ vs = hs.fetch("a", nil)
106+ puts vs.nil? ? "missing-str" : "found-str-#{vs}"
107+
108+ hsm = {}
109+ vsm = hsm.fetch("a", nil)
110+ puts vsm.nil? ? "missing-str-key" : "found-str-bad"
111+end
112+t_fetch_nil_default_distinguishes_zero
113+
114+# === stdlib ===
115+def t_stdlib
116+ # Array#join
117+ arr = (1..5).to_a
118+ puts arr.join(", ")
119+
120+ # Array#uniq
121+ nums = (1..5).to_a
122+ nums.push(3)
123+ nums.push(1)
124+ uniq = nums.uniq
125+ puts uniq.length
126+
127+ # srand/rand
128+ srand(0)
129+ r = rand(100)
130+ puts r >= 0
131+
132+ # ARGV.length
133+ puts ARGV.length
134+
135+ # $stderr.puts
136+ $stderr.puts("stderr msg")
137+
138+ puts "done"
139+end
140+t_stdlib
141+
142+# === math_fn_parity ===
143+def t_math_fn_parity
144+ # End-to-end exercise of every recognized Math fn.
145+ puts Math.sqrt(16.0).to_i.to_s
146+ puts Math.cos(0.0).to_i.to_s
147+ puts Math.sin(0.0).to_i.to_s
148+ puts Math.tan(0.0).to_i.to_s
149+ puts Math.acos(1.0).to_i.to_s
150+ puts Math.asin(0.0).to_i.to_s
151+ puts Math.atan(0.0).to_i.to_s
152+ puts Math.sinh(0.0).to_i.to_s
153+ puts Math.cosh(0.0).to_i.to_s
154+ puts Math.tanh(0.0).to_i.to_s
155+ puts Math.asinh(0.0).to_i.to_s
156+ puts Math.acosh(1.0).to_i.to_s
157+ puts Math.atanh(0.0).to_i.to_s
158+ puts Math.log(1.0).to_i.to_s
159+ puts Math.log2(1.0).to_i.to_s
160+ puts Math.log10(1.0).to_i.to_s
161+ puts Math.exp(0.0).to_i.to_s
162+ puts Math.atan2(0.0, 1.0).to_i.to_s
163+ puts Math.hypot(3.0, 4.0).to_i.to_s
164+end
165+t_math_fn_parity