1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove any precision problem by comparing the float values

Rational values are move precise than float values so when comparing
rationals values may be off by a few units that are hard to assert
equality. Let's make sure we are comparing the float value with float
values.
This commit is contained in:
Rafael Mendonça França 2019-09-30 23:20:22 -04:00
parent 8fdbc2ae22
commit 57ae917e9d

View file

@ -114,13 +114,15 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal Rational(1, 1_000_000_000), time.sec_fraction
time = Time.utc(2016, 4, 23, 0, 0, 0.000_000_001)
assert_equal 0.000_000_001.to_r, time.sec_fraction
assert_kind_of Rational, time.sec_fraction
assert_equal 0.000_000_001, time.sec_fraction.to_f
time = Time.utc(2016, 4, 23, 0, 0, 0, Rational(1, 1_000))
assert_equal Rational(1, 1_000_000_000), time.sec_fraction
time = Time.utc(2016, 4, 23, 0, 0, 0, 0.001)
assert_equal 0.001.to_r / 1000000, time.sec_fraction
assert_kind_of Rational, time.sec_fraction
assert_equal 0.001.to_r / 1000000, time.sec_fraction.to_f
end
def test_beginning_of_day