I have a minitest test that is asserting if a decimal is the same. Wondering why this
My assert code:
assert_equal -9.04, elts[2].change.round(2)
Failure:
Failure: LeaveTypePolicyTest#test_case_12 [/usr/src/app/test/models/leave_type_policy_test.rb:1007] Minitest::Assertion: Expected: -9.04 Actual: -0.904e1
Anyone experienced this? and perhaps why its failing? I have many many tests doing similar assertions, but only this for some reason fails.
Use
assert_in_delta, for example:SEE ALSO: Test::Unit::Assertions#assert_in_delta: https://www.rubydoc.info/github/test-unit/test-unit/Test%2FUnit%2FAssertions:assert_in_delta
For example, this passes:
It is possible that the initial test failure was caused by comparing
floattoBigDecimalor something similar to that. Apparently, Ruby needs the classes in such a comparison to match. Here is a simple example that reproduces a similar behavior: