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 > 0
3-
4-# Without .to_f: Time.now.to_i is whole seconds. In a tight loop of
5-# 100 samples virtually every read lands in the same second (the loop
6-# runs in << 1s). Cap at 1 so the output is deterministic.
7-secs = []
8-i = 0
9-while i < 100
10- secs.push(Time.now.to_i)
11- i = i + 1
12-end
13-sn = secs.uniq.length
14-if sn > 1
15- sn = 1
16-end
17-puts sn
18-
19-# With .to_f: Time.now.to_f is float seconds with sub-second precision.
20-# Scale the fractional part to microseconds; virtually every sample
21-# 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. With
23-# clock_gettime nanosecond resolution we see many. Cap at 2 so the
24-# output is deterministic: 1 = no sub-second precision, 2 = present.
25-micros = []
26-i = 0
27-while i < 100
28- s = Time.now
29- micros.push(((s.to_f - s.to_i) * 1_000_000).to_i)
30- i = i + 1
31-end
32-mn = micros.uniq.length
33-if mn > 2
34- mn = 2
35-end
36-puts mn
37-
1+t = Time.now
2+puts t.to_f - t.to_i > 0.0
383 puts "done"