[前][次][番号順一覧][スレッド一覧]

ruby-changes:62189

From: Kenta <ko1@a...>
Date: Sun, 12 Jul 2020 17:30:51 +0900 (JST)
Subject: [ruby-changes:62189] 9b433d34da (master): bidecimal: improve tests' independence (#3297)

https://git.ruby-lang.org/ruby.git/commit/?id=9b433d34da

From 9b433d34da90b0e706a388fe67cdfc386a8c2212 Mon Sep 17 00:00:00 2001
From: Kenta Murata <mrkn@u...>
Date: Sun, 12 Jul 2020 17:30:29 +0900
Subject: 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.

diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb
index 4d53575..11174ad 100644
--- a/test/bigdecimal/test_bigdecimal.rb
+++ b/test/bigdecimal/test_bigdecimal.rb
@@ -334,6 +334,8 @@ class TestBigDecimal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L334
   end
 
   def test_save_rounding_mode
+    saved_mode = BigDecimal.mode(BigDecimal::ROUND_MODE)
+
     BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_FLOOR)
     BigDecimal.save_rounding_mode do
       BigDecimal.mode(BigDecimal::ROUND_MODE, BigDecimal::ROUND_HALF_EVEN)
@@ -341,6 +343,8 @@ class TestBigDecimal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L343
     assert_equal(BigDecimal::ROUND_FLOOR, BigDecimal.mode(BigDecimal::ROUND_MODE))
 
     assert_equal(42, BigDecimal.save_rounding_mode { 42 })
+  ensure
+    BigDecimal.mode(BigDecimal::ROUND_MODE, saved_mode)
   end
 
   def test_save_limit
diff --git a/test/bigdecimal/test_bigdecimal_util.rb b/test/bigdecimal/test_bigdecimal_util.rb
index c4d5816..7c0830e 100644
--- a/test/bigdecimal/test_bigdecimal_util.rb
+++ b/test/bigdecimal/test_bigdecimal_util.rb
@@ -61,15 +61,19 @@ class TestBigDecimalUtil < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal_util.rb#L61
   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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]