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.now2-
puts t.to_i > 0 # true2+
3+
# Basic shape: positive integer seconds and positive float seconds.4+
puts t.to_i > 05+
puts t.to_f > 0.06+
7+
# to_f >= to_i (to_i truncates the fractional part).8+
puts t.to_f >= t.to_i9+
10+
# Millisecond idiom: (Time.now.to_f * 1000).to_i is the wall-clock ms11+
# count; must be positive and at least seconds*1000.12+
ms = (t.to_f * 1000).to_i13+
puts ms > 014+
puts ms >= t.to_i * 100015+
16+
# Two consecutive reads don't go backward.17+
a = Time.now18+
b = Time.now19+
puts b >= a20+
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 of24+
# all 50 hitting tv_nsec == 0 are effectively zero.25+
found = false26+
i = 027+
while i < 5028+
s = Time.now29+
if s.to_f != s.to_i.to_f30+
found = true31+
end32+
i = i + 133+
end34+
puts found35+
336
puts "done"test/time_to_f.rbdeleted
Loading diff…