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

ruby-changes:64353

From: Nobuyoshi <ko1@a...>
Date: Sun, 20 Dec 2020 03:17:07 +0900 (JST)
Subject: [ruby-changes:64353] ed4381d941 (master): BigDecimal#precs is deprecated

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

From ed4381d94132990067922bc4204c8abb99cde3e8 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 20 Dec 2020 03:14:58 +0900
Subject: BigDecimal#precs is deprecated


diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
index 5da0210..b265e84 100644
--- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
+++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
@@ -30,13 +30,15 @@ describe "Kernel#BigDecimal" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/BigDecimal_spec.rb#L30
     BigDecimal(rational, 100).to_s.should == "0.99999999999999999999e18"
   end
 
-  it "accepts significant digits >= given precision" do
-    BigDecimal("3.1415923", 10).precs[1].should >= 10
-  end
+  ruby_version_is ""..."3.0" do
+    it "accepts significant digits >= given precision" do
+      BigDecimal("3.1415923", 10).precs[1].should >= 10
+    end
 
-  it "determines precision from initial value" do
-    pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
-    BigDecimal(pi_string).precs[1].should >= pi_string.size-1
+    it "determines precision from initial value" do
+      pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
+      BigDecimal(pi_string).precs[1].should >= pi_string.size-1
+    end
   end
 
   it "ignores leading and trailing whitespace" do
@@ -223,12 +225,14 @@ describe "Kernel#BigDecimal" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/BigDecimal_spec.rb#L225
       Float(@b).to_s.should == "166.66666666666666"
     end
 
-    it "has the expected precision on the LHS" do
-      @a.precs[0].should == 18
-    end
+    ruby_version_is ""..."3.0" do
+      it "has the expected precision on the LHS" do
+        @a.precs[0].should == 18
+      end
 
-    it "has the expected maximum precision on the LHS" do
-      @a.precs[1].should == 27
+      it "has the expected maximum precision on the LHS" do
+        @a.precs[1].should == 27
+      end
     end
 
     it "produces the expected result when done via Float" do
@@ -241,32 +245,36 @@ describe "Kernel#BigDecimal" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/BigDecimal_spec.rb#L245
 
     # Check underlying methods work as we understand
 
-    it "BigDecimal precision is the number of digits rounded up to a multiple of nine" do
-      1.upto(100) do |n|
-        b = BigDecimal('4' * n)
-        precs, _ = b.precs
-        (precs >= 9).should be_true
-        (precs >= n).should be_true
-        (precs % 9).should == 0
+    ruby_version_is ""..."3.0" do
+      it "BigDecimal precision is the number of digits rounded up to a multiple of nine" do
+        1.upto(100) do |n|
+          b = BigDecimal('4' * n)
+          precs, _ = b.precs
+          (precs >= 9).should be_true
+          (precs >= n).should be_true
+          (precs % 9).should == 0
+        end
+        BigDecimal('NaN').precs[0].should == 9
       end
-      BigDecimal('NaN').precs[0].should == 9
-    end
 
-    it "BigDecimal maximum precision is nine more than precision except for abnormals" do
-      1.upto(100) do |n|
-        b = BigDecimal('4' * n)
-        precs, max = b.precs
-        max.should == precs + 9
+      it "BigDecimal maximum precision is nine more than precision except for abnormals" do
+        1.upto(100) do |n|
+          b = BigDecimal('4' * n)
+          precs, max = b.precs
+          max.should == precs + 9
+        end
+        BigDecimal('NaN').precs[1].should == 9
       end
-      BigDecimal('NaN').precs[1].should == 9
     end
 
     it "BigDecimal(Rational, 18) produces the result we expect" do
       BigDecimal(@b, 18).to_s.should == "0.166666666666666667e3"
     end
 
-    it "BigDecimal(Rational, BigDecimal.precs[0]) produces the result we expect" do
-      BigDecimal(@b, @a.precs[0]).to_s.should == "0.166666666666666667e3"
+    ruby_version_is ""..."3.0" do
+      it "BigDecimal(Rational, BigDecimal.precs[0]) produces the result we expect" do
+        BigDecimal(@b, @a.precs[0]).to_s.should == "0.166666666666666667e3"
+      end
     end
 
     # Check the top-level expression works as we expect
diff --git a/spec/ruby/library/bigdecimal/precs_spec.rb b/spec/ruby/library/bigdecimal/precs_spec.rb
index 78a6234..8809d09 100644
--- a/spec/ruby/library/bigdecimal/precs_spec.rb
+++ b/spec/ruby/library/bigdecimal/precs_spec.rb
@@ -1,48 +1,50 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/precs_spec.rb#L1
 require_relative '../../spec_helper'
 require 'bigdecimal'
 
-describe "BigDecimal#precs" do
+ruby_version_is ""..."3.0" do
+  describe "BigDecimal#precs" do
 
-  before :each do
-    @infinity = BigDecimal("Infinity")
-    @infinity_neg = BigDecimal("-Infinity")
-    @nan = BigDecimal("NaN")
-    @zero = BigDecimal("0")
-    @zero_neg = BigDecimal("-0")
+    before :each do
+      @infinity = BigDecimal("Infinity")
+      @infinity_neg = BigDecimal("-Infinity")
+      @nan = BigDecimal("NaN")
+      @zero = BigDecimal("0")
+      @zero_neg = BigDecimal("-0")
 
-    @arr = [BigDecimal("2E40001"), BigDecimal("3E-20001"),\
-            @infinity, @infinity_neg, @nan, @zero, @zero_neg]
-    @precision = BigDecimal::BASE.to_s.length - 1
-  end
+      @arr = [BigDecimal("2E40001"), BigDecimal("3E-20001"),\
+              @infinity, @infinity_neg, @nan, @zero, @zero_neg]
+      @precision = BigDecimal::BASE.to_s.length - 1
+    end
 
-  it "returns array of two values" do
-    @arr.each do |x|
-      x.precs.kind_of?(Array).should == true
-      x.precs.size.should == 2
+    it "returns array of two values" do
+      @arr.each do |x|
+        x.precs.kind_of?(Array).should == true
+        x.precs.size.should == 2
+      end
     end
-  end
 
-  it "returns Integers as array values" do
-    @arr.each do |x|
-      x.precs[0].kind_of?(Integer).should == true
-      x.precs[1].kind_of?(Integer).should == true
+    it "returns Integers as array values" do
+      @arr.each do |x|
+        x.precs[0].kind_of?(Integer).should == true
+        x.precs[1].kind_of?(Integer).should == true
+      end
     end
-  end
 
-  it "returns the current value of significant digits as the first value" do
-    BigDecimal("3.14159").precs[0].should >= 6
-    BigDecimal('1').precs[0].should == BigDecimal('1' + '0' * 100).precs[0]
-    [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
-      value.precs[0].should <= @precision
+    it "returns the current value of significant digits as the first value" do
+      BigDecimal("3.14159").precs[0].should >= 6
+      BigDecimal('1').precs[0].should == BigDecimal('1' + '0' * 100).precs[0]
+      [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
+        value.precs[0].should <= @precision
+      end
     end
-  end
 
-  it "returns the maximum number of significant digits as the second value" do
-    BigDecimal("3.14159").precs[1].should >= 6
-    BigDecimal('1').precs[1].should >= 1
-    BigDecimal('1' + '0' * 100).precs[1].should >= 101
-    [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
-      value.precs[1].should >= 1
+    it "returns the maximum number of significant digits as the second value" do
+      BigDecimal("3.14159").precs[1].should >= 6
+      BigDecimal('1').precs[1].should >= 1
+      BigDecimal('1' + '0' * 100).precs[1].should >= 101
+      [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
+        value.precs[1].should >= 1
+      end
     end
   end
 end
-- 
cgit v0.10.2


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

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