Commit c41e250d
c41e250d3235Merged
Richard Ramsden <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
Simplify test/time.rb to a single fractional-part assert
Drop the bucket-count theatre — that was a boolean dressed up as a number. The actual fact under test is "Time.now.to_f has a non-zero sub-second fractional part," so just assert that directly.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- c41e250d3235
- Parent
- d8c107acbd55
test/time.rbmodifiedView file
@@ -1,38 +1,3 @@
1-
# Smoke: Time.now compiles and yields a positive timestamp.2-
puts Time.now.to_i > 03-
4-
# Without .to_f: Time.now.to_i is whole seconds. In a tight loop of5-
# 100 samples virtually every read lands in the same second (the loop6-
# runs in << 1s). Cap at 1 so the output is deterministic.7-
secs = []8-
i = 09-
while i < 10010-
secs.push(Time.now.to_i)11-
i = i + 112-
end13-
sn = secs.uniq.length14-
if sn > 115-
sn = 116-
end17-
puts sn18-
19-
# With .to_f: Time.now.to_f is float seconds with sub-second precision.20-
# Scale the fractional part to microseconds; virtually every sample21-
# lands in a distinct bucket. Pre-fix Time.now was whole-second mrb_int,22-
# so every sample's microsecond bucket was 0 → 1 distinct value. With23-
# clock_gettime nanosecond resolution we see many. Cap at 2 so the24-
# output is deterministic: 1 = no sub-second precision, 2 = present.25-
micros = []26-
i = 027-
while i < 10028-
s = Time.now29-
micros.push(((s.to_f - s.to_i) * 1_000_000).to_i)30-
i = i + 131-
end32-
mn = micros.uniq.length33-
if mn > 234-
mn = 235-
end36-
puts mn37-
1+
t = Time.now2+
puts t.to_f - t.to_i > 0.0383
puts "done"