Commit b601e9e5
b601e9e5f871Merged
Richard Ramsden <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
Strengthen time_to_f test to actually verify sub-second precision
Original asserts only checked > 0, which the old whole-second Time.now also satisfies — so the test would have passed even without the fix. Add a sampling loop checking that t.to_f != t.to_i.to_f for at least one of 50 samples; this is false for every sample under the old int codegen and effectively always true under clock_gettime.
Verified by temporarily reverting the codegen line: the new check fails
(prints false), CRuby prints true, comparison fails as intended.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- b601e9e5f871
- Parent
- c1a5d3048017
test/time_to_f.rbmodifiedView file
@@ -3,4 +3,18 @@
33
puts t.to_f > 0.044
ms = (Time.now.to_f * 1000).to_i55
puts ms > 06+
7+
# Sub-second precision: pre-fix Time.now returned whole-second mrb_int,8+
# so t.to_f always equalled t.to_i.to_f. With clock_gettime resolution,9+
# at least one of 50 samples will have a nonzero fractional component.10+
found = false11+
i = 012+
while i < 5013+
s = Time.now14+
if s.to_f != s.to_i.to_f15+
found = true16+
end17+
i = i + 118+
end19+
puts found620
puts "done"