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.0
44 ms = (Time.now.to_f * 1000).to_i
55 puts ms > 0
6+
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 = false
11+i = 0
12+while i < 50
13+ s = Time.now
14+ if s.to_f != s.to_i.to_f
15+ found = true
16+ end
17+ i = i + 1
18+end
19+puts found
620 puts "done"