summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-12-20 03:14:58 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-12-20 03:14:58 +0900
commited4381d94132990067922bc4204c8abb99cde3e8 (patch)
tree87bdab35f7bf26465e696f802edd1f36a7e6dba4 /spec
parentc01ad11f908c2a57c2348e83d109b08fdd89dc4e (diff)
BigDecimal#precs is deprecated
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/library/bigdecimal/BigDecimal_spec.rb64
-rw-r--r--spec/ruby/library/bigdecimal/precs_spec.rb68
2 files changed, 71 insertions, 61 deletions
diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
index 5da0210145..b265e84798 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
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
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
# 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 78a62341e8..8809d094ef 100644
--- a/spec/ruby/library/bigdecimal/precs_spec.rb
+++ b/spec/ruby/library/bigdecimal/precs_spec.rb
@@ -1,48 +1,50 @@
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