diff options
author | Benoit Daloze <[email protected]> | 2020-12-27 17:35:32 +0100 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2020-12-27 17:35:32 +0100 |
commit | 727c97da1977544c91b9b3677811da3a44af7d53 (patch) | |
tree | 4f027117edad10789db57ff4b83242753a89e39d /spec/ruby/library/bigdecimal | |
parent | 267bed0cd91711e2a8c79219e97431ba22137b01 (diff) |
Update to ruby/spec@4ce9f41
Diffstat (limited to 'spec/ruby/library/bigdecimal')
-rw-r--r-- | spec/ruby/library/bigdecimal/BigDecimal_spec.rb | 64 | ||||
-rw-r--r-- | spec/ruby/library/bigdecimal/add_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/library/bigdecimal/precs_spec.rb | 39 | ||||
-rw-r--r-- | spec/ruby/library/bigdecimal/shared/to_int.rb | 2 |
4 files changed, 55 insertions, 54 deletions
diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb index b265e84798..d56c0a664b 100644 --- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb +++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb @@ -30,15 +30,17 @@ describe "Kernel#BigDecimal" do BigDecimal(rational, 100).to_s.should == "0.99999999999999999999e18" end - ruby_version_is ""..."3.0" do - it "accepts significant digits >= given precision" do + it "accepts significant digits >= given precision" do + suppress_warning do BigDecimal("3.1415923", 10).precs[1].should >= 10 end + end - it "determines precision from initial value" do - pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043" - BigDecimal(pi_string).precs[1].should >= pi_string.size-1 - end + it "determines precision from initial value" do + pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043" + suppress_warning { + BigDecimal(pi_string).precs[1] + }.should >= pi_string.size-1 end it "ignores leading and trailing whitespace" do @@ -225,14 +227,12 @@ describe "Kernel#BigDecimal" do Float(@b).to_s.should == "166.66666666666666" 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 precision on the LHS" do + suppress_warning { @a.precs[0] }.should == 18 + end - it "has the expected maximum precision on the LHS" do - @a.precs[1].should == 27 - end + it "has the expected maximum precision on the LHS" do + suppress_warning { @a.precs[1] }.should == 27 end it "produces the expected result when done via Float" do @@ -245,36 +245,32 @@ describe "Kernel#BigDecimal" do # Check underlying methods work as we understand - 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 + 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, _ = suppress_warning { b.precs } + (precs >= 9).should be_true + (precs >= n).should be_true + (precs % 9).should == 0 end + suppress_warning { 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 - end - BigDecimal('NaN').precs[1].should == 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 = suppress_warning { b.precs } + max.should == precs + 9 end + suppress_warning { 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 - 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 + it "BigDecimal(Rational, BigDecimal.precs[0]) produces the result we expect" do + BigDecimal(@b, suppress_warning { @a.precs[0] }).to_s.should == "0.166666666666666667e3" end # Check the top-level expression works as we expect diff --git a/spec/ruby/library/bigdecimal/add_spec.rb b/spec/ruby/library/bigdecimal/add_spec.rb index f844ca96fa..bea8b8f764 100644 --- a/spec/ruby/library/bigdecimal/add_spec.rb +++ b/spec/ruby/library/bigdecimal/add_spec.rb @@ -41,14 +41,14 @@ describe "BigDecimal#add" do @frac_3.add(@frac_4, 6).should == BigDecimal("0.11111E16") end - it "returns a + [Integer value] with given precision" do + it "returns a + [Fixnum value] with given precision" do (1..10).each {|precision| @dot_ones.add(0, precision).should == BigDecimal("0." + "1" * precision) } BigDecimal("0.88").add(0, 1).should == BigDecimal("0.9") end - it "returns a + [Integer value] with given precision" do + it "returns a + [Bignum value] with given precision" do bignum = 10000000000000000000 (1..20).each {|precision| @dot_ones.add(bignum, precision).should == BigDecimal("0.1E20") diff --git a/spec/ruby/library/bigdecimal/precs_spec.rb b/spec/ruby/library/bigdecimal/precs_spec.rb index 8809d094ef..5fda8d3087 100644 --- a/spec/ruby/library/bigdecimal/precs_spec.rb +++ b/spec/ruby/library/bigdecimal/precs_spec.rb @@ -1,44 +1,49 @@ require_relative '../../spec_helper' require 'bigdecimal' -ruby_version_is ""..."3.0" do - describe "BigDecimal#precs" 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 + it "returns array of two values" do + suppress_warning 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 + it "returns Integers as array values" do + suppress_warning 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 + it "returns the current value of significant digits as the first value" do + suppress_warning 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 + it "returns the maximum number of significant digits as the second value" do + suppress_warning do BigDecimal("3.14159").precs[1].should >= 6 BigDecimal('1').precs[1].should >= 1 BigDecimal('1' + '0' * 100).precs[1].should >= 101 diff --git a/spec/ruby/library/bigdecimal/shared/to_int.rb b/spec/ruby/library/bigdecimal/shared/to_int.rb index 41dd200b9f..0f16251612 100644 --- a/spec/ruby/library/bigdecimal/shared/to_int.rb +++ b/spec/ruby/library/bigdecimal/shared/to_int.rb @@ -6,7 +6,7 @@ describe :bigdecimal_to_int , shared: true do -> { BigDecimal("NaN").send(@method) }.should raise_error(FloatDomainError) end - it "returns Integer or Integer otherwise" do + it "returns Integer otherwise" do BigDecimal("3E-20001").send(@method).should == 0 BigDecimal("2E4000").send(@method).should == 2 * 10 ** 4000 BigDecimal("2").send(@method).should == 2 |