diff options
author | Kenta Murata <mrkn@mrkn.jp> | 2019-10-09 10:39:39 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-07-06 01:15:46 +0900 |
commit | 03a33603c66bf6eca6937d221f87daf3f5a489f7 (patch) | |
tree | 5edac3f58fed2349428a37d12d23aee34954658a /test | |
parent | 6607212224401d852c0056b841be7ff95236e8f7 (diff) |
[ruby/bigdecimal] Add Complex#to_d
https://github.com/ruby/bigdecimal/commit/97e794ac97
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3295
Diffstat (limited to 'test')
-rw-r--r-- | test/bigdecimal/test_bigdecimal_util.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/bigdecimal/test_bigdecimal_util.rb b/test/bigdecimal/test_bigdecimal_util.rb index b963fcdeeb..c4d5816987 100644 --- a/test/bigdecimal/test_bigdecimal_util.rb +++ b/test/bigdecimal/test_bigdecimal_util.rb @@ -60,6 +60,18 @@ class TestBigDecimalUtil < Test::Unit::TestCase assert_raise(ArgumentError) { 355.quo(113).to_d(-42) } 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)) + + 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 + def test_String_to_d assert_equal(BigDecimal('1'), "1__1_1".to_d) assert_equal(BigDecimal('2.5'), "2.5".to_d) |