Skip to content

Commit

Permalink
[test] few round half-to-even asserts for sprintf
Browse files Browse the repository at this point in the history
since this seems to be a failure point for JRuby (jrubyGH-5556)
  • Loading branch information
kares committed Jan 29, 2019
1 parent 2cc4dbb commit e22e713
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/jruby/test_sprintf.rb
Expand Up @@ -15,5 +15,26 @@ def test_sprintf_two
s = format("%01.0f", n).to_s
assert(s === "1234567892", "Test failed, value of #{s} did not match '1234567892'.")
end

def test_round_half_even
assert_equal("5.00", sprintf("%.2f",5.005))
assert_equal("5.01", sprintf("%.2f",5.0059))
assert_equal("5.01", sprintf("%.2f",5.0051))
assert_equal("5.00", sprintf("%.2f",5.0050))
assert_equal("5.01", sprintf("%.2f",5.00501))
assert_equal("5.000", sprintf("%.3f",5.0005))

assert_equal("5.02", sprintf("%.2f",5.015))
assert_equal("5.02", sprintf("%.2f",5.025))

assert_equal("97.66A", "%.2fA" % 97.6562)
assert_equal("29.56B", "%.2fB" % 29.5562)

assert_equal "28.554", sprintf("%.3f", 28.5535)
assert_equal "97.7X", sprintf("%.1fX", 97.65625)

assert_equal("28.554", "%.3f" % 28.5535)
assert_equal("97.7X", "%.1fX" % 97.65625)
end
end

0 comments on commit e22e713

Please sign in to comment.