mirror of
https://github.com/ruby/ruby.git
synced 2025-09-19 18:43:59 +02:00
* process.c (make_clock_result): add :second as a unit for
Process.clock_gettime. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44230 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b7cbdcc5fd
commit
2a732947a6
3 changed files with 32 additions and 0 deletions
|
@ -1682,6 +1682,29 @@ EOS
|
|||
assert_raise(Errno::EINVAL) { Process.clock_gettime(:foo) }
|
||||
end
|
||||
|
||||
def test_clock_gettime_unit
|
||||
t0 = Time.now.to_f
|
||||
[
|
||||
[:nanosecond, 1_000_000_000],
|
||||
[:microsecond, 1_000_000],
|
||||
[:millisecond, 1_000],
|
||||
[:second, 1],
|
||||
[:float_microsecond, 1_000_000.0],
|
||||
[:float_millisecond, 1_000.0],
|
||||
[:float_second, 1.0],
|
||||
[nil, 1.0],
|
||||
[:foo],
|
||||
].each do |unit, num|
|
||||
unless num
|
||||
assert_raise(ArgumentError){ Process.clock_gettime(Process::CLOCK_REALTIME, unit) }
|
||||
next
|
||||
end
|
||||
t1 = Process.clock_gettime(Process::CLOCK_REALTIME, unit)
|
||||
assert_kind_of num.class, t1, [unit, num].inspect
|
||||
assert_in_delta t0, t1/num, 1, [unit, num].inspect
|
||||
end
|
||||
end
|
||||
|
||||
def test_clock_gettime_constants
|
||||
Process.constants.grep(/\ACLOCK_/).each {|n|
|
||||
c = Process.const_get(n)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue