Commit 9ed607d1

9ed607d1e910Merged

Richard Ramsden <[email protected]> · 6 months ago · 2 files · ~1 modified · -1 deleted

Description

Consolidate Time tests into a single time.rb suite

Merge test/time_to_f.rb into test/time.rb and broaden coverage: basic shape (to_i, to_f positive), to_f >= to_i consistency, the millisecond idiom (positive and >= seconds*1000), monotonicity of two consecutive reads, and the existing sub-second precision check.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
9ed607d1e910
Parent
b601e9e5f871

test/time.rbmodifiedView file

@@ -1,3 +1,36 @@
11 t = Time.now
2-puts t.to_i > 0 # true
2+
3+# Basic shape: positive integer seconds and positive float seconds.
4+puts t.to_i > 0
5+puts t.to_f > 0.0
6+
7+# to_f >= to_i (to_i truncates the fractional part).
8+puts t.to_f >= t.to_i
9+
10+# Millisecond idiom: (Time.now.to_f * 1000).to_i is the wall-clock ms
11+# count; must be positive and at least seconds*1000.
12+ms = (t.to_f * 1000).to_i
13+puts ms > 0
14+puts ms >= t.to_i * 1000
15+
16+# Two consecutive reads don't go backward.
17+a = Time.now
18+b = Time.now
19+puts b >= a
20+
21+# Sub-second precision: pre-fix Time.now returned whole-second mrb_int,
22+# so t.to_f always equalled t.to_i.to_f. With clock_gettime resolution,
23+# at least one of 50 samples has a nonzero fractional part — odds of
24+# all 50 hitting tv_nsec == 0 are effectively zero.
25+found = false
26+i = 0
27+while i < 50
28+ s = Time.now
29+ if s.to_f != s.to_i.to_f
30+ found = true
31+ end
32+ i = i + 1
33+end
34+puts found
35+
336 puts "done"