diff options
author | Kenta Murata <mrkn@users.noreply.github.com> | 2020-07-12 17:30:29 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-12 17:30:29 +0900 |
commit | 9b433d34da90b0e706a388fe67cdfc386a8c2212 (patch) | |
tree | 1bacc3d768d20495728a4cfa2e983d1fbdcdbfd0 /test/bigdecimal/test_bigdecimal_util.rb | |
parent | 3b96ad9b54455aef66edd758fa1ef931fa748ce5 (diff) |
bidecimal: improve tests' independence (#3297)
Tests depending on the rounding mode must specify the appropriate rounding
mode and restore to the original mode at the end.
Notes
Notes:
Merged-By: mrkn <mrkn@ruby-lang.org>
Diffstat (limited to 'test/bigdecimal/test_bigdecimal_util.rb')
-rw-r--r-- | test/bigdecimal/test_bigdecimal_util.rb | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/test/bigdecimal/test_bigdecimal_util.rb b/test/bigdecimal/test_bigdecimal_util.rb index c4d5816987..7c0830e96c 100644 --- a/test/bigdecimal/test_bigdecimal_util.rb +++ b/test/bigdecimal/test_bigdecimal_util.rb @@ -61,15 +61,19 @@ class TestBigDecimalUtil < Test::Unit::TestCase end def test_Complex_to_d - assert_equal(BigDecimal("1"), Complex(1, 0).to_d) - assert_equal(BigDecimal("0.333333333333333333333"), - Complex(1.quo(3), 0).to_d(21)) - assert_equal(BigDecimal("0.1234567"), Complex(0.1234567, 0).to_d) - assert_equal(BigDecimal("0.1235"), Complex(0.1234567, 0).to_d(4)) + BigDecimal.save_rounding_mode do + BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_HALF_EVEN) - assert_raise_with_message(ArgumentError, "can't omit precision for a Rational.") { Complex(1.quo(3), 0).to_d } + assert_equal(BigDecimal("1"), Complex(1, 0).to_d) + assert_equal(BigDecimal("0.333333333333333333333"), + Complex(1.quo(3), 0).to_d(21)) + assert_equal(BigDecimal("0.1234567"), Complex(0.1234567, 0).to_d) + assert_equal(BigDecimal("0.1235"), Complex(0.1234567, 0).to_d(4)) - assert_raise_with_message(ArgumentError, "Unable to make a BigDecimal from non-zero imaginary number") { Complex(1, 1).to_d } + assert_raise_with_message(ArgumentError, "can't omit precision for a Rational.") { Complex(1.quo(3), 0).to_d } + + assert_raise_with_message(ArgumentError, "Unable to make a BigDecimal from non-zero imaginary number") { Complex(1, 1).to_d } + end end def test_String_to_d |