diff options
author | Andreas Eger <dev@eger-andreas.de> | 2016-12-11 03:30:08 +0100 |
---|---|---|
committer | Andreas Eger <dev@eger-andreas.de> | 2017-05-13 21:38:15 +0200 |
commit | ad203bcb2be17e06909ab6d67ab2475673673bbc (patch) | |
tree | 337493888b00b12e03ca6050808cf62d51d2eda0 /ruby/tests | |
parent | 455b61c6b0f39ac269b26969877dd3c6f3e32270 (diff) | |
download | protobuf-ad203bcb2be17e06909ab6d67ab2475673673bbc.tar.gz protobuf-ad203bcb2be17e06909ab6d67ab2475673673bbc.tar.bz2 protobuf-ad203bcb2be17e06909ab6d67ab2475673673bbc.zip |
fix floating point accuracy problem in Timestamp#to_f
`.quo` return the most exact devision which fixes accuracy problems for the
timestamp coercion
Diffstat (limited to 'ruby/tests')
-rw-r--r-- | ruby/tests/well_known_types_test.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/ruby/tests/well_known_types_test.rb b/ruby/tests/well_known_types_test.rb index 9b46632b..ad8531d9 100644 --- a/ruby/tests/well_known_types_test.rb +++ b/ruby/tests/well_known_types_test.rb @@ -13,10 +13,15 @@ class TestWellKnownTypes < Test::Unit::TestCase assert_equal Time.at(12345), ts.to_time assert_equal 12345, ts.to_i - ts.from_time(Time.at(123456, 654321)) + time = Time.at(123456, 654321) + ts.from_time(time) assert_equal 123456, ts.seconds assert_equal 654321000, ts.nanos - assert_equal Time.at(123456.654321), ts.to_time + assert_equal time, ts.to_time + + time = Time.now + ts.from_time(time) + assert_equal time.to_f, ts.to_time.to_f end def test_duration |