summaryrefslogtreecommitdiff
path: root/spec/ruby/library/bigdecimal
diff options
context:
space:
mode:
authorBenoit Daloze <[email protected]>2019-06-27 21:02:36 +0200
committerBenoit Daloze <[email protected]>2019-06-27 21:02:36 +0200
commitd80e44deec77678fe2d72f94c17b2409b3e794d5 (patch)
tree612bf2313550e0982dda452f48492cc069e1c21a /spec/ruby/library/bigdecimal
parentc940397116c5aef76b1c0d05561c11d43ef596a7 (diff)
Update to ruby/spec@8d74d49
Diffstat (limited to 'spec/ruby/library/bigdecimal')
-rw-r--r--spec/ruby/library/bigdecimal/BigDecimal_spec.rb7
-rw-r--r--spec/ruby/library/bigdecimal/inspect_spec.rb6
-rw-r--r--spec/ruby/library/bigdecimal/to_d_spec.rb1
-rw-r--r--spec/ruby/library/bigdecimal/to_s_spec.rb6
4 files changed, 18 insertions, 2 deletions
diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
index 98b3f47703..ec38c6f113 100644
--- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
+++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
@@ -150,8 +150,13 @@ describe "Kernel#BigDecimal" do
BigDecimal("-12345.6E-1").should == -reference
end
- it 'raises ArgumentError when Float is used without precision' do
+ it "raises ArgumentError when Float is used without precision" do
lambda { BigDecimal(1.0) }.should raise_error(ArgumentError)
end
+ it "returns appropriate BigDecimal zero for signed zero" do
+ BigDecimal(-0.0, Float::DIG).sign.should == -1
+ BigDecimal(0.0, Float::DIG).sign.should == 1
+ end
+
end
diff --git a/spec/ruby/library/bigdecimal/inspect_spec.rb b/spec/ruby/library/bigdecimal/inspect_spec.rb
index 18e9ca9a0c..7ce47142b2 100644
--- a/spec/ruby/library/bigdecimal/inspect_spec.rb
+++ b/spec/ruby/library/bigdecimal/inspect_spec.rb
@@ -15,6 +15,12 @@ describe "BigDecimal#inspect" do
@bigdec.inspect.should == "0.12345678e4"
end
+ it "does not add an exponent for zero values" do
+ BigDecimal("0").inspect.should == "0.0"
+ BigDecimal("+0").inspect.should == "0.0"
+ BigDecimal("-0").inspect.should == "-0.0"
+ end
+
it "properly cases non-finite values" do
BigDecimal("NaN").inspect.should == "NaN"
BigDecimal("Infinity").inspect.should == "Infinity"
diff --git a/spec/ruby/library/bigdecimal/to_d_spec.rb b/spec/ruby/library/bigdecimal/to_d_spec.rb
index 8e20901fd9..50aea99bf7 100644
--- a/spec/ruby/library/bigdecimal/to_d_spec.rb
+++ b/spec/ruby/library/bigdecimal/to_d_spec.rb
@@ -2,7 +2,6 @@ require_relative '../../spec_helper'
require 'bigdecimal'
require 'bigdecimal/util'
-
describe "Float#to_d" do
it "returns appropriate BigDecimal zero for signed zero" do
-0.0.to_d.sign.should == -1
diff --git a/spec/ruby/library/bigdecimal/to_s_spec.rb b/spec/ruby/library/bigdecimal/to_s_spec.rb
index 247db1a5d2..c7ee6a01b0 100644
--- a/spec/ruby/library/bigdecimal/to_s_spec.rb
+++ b/spec/ruby/library/bigdecimal/to_s_spec.rb
@@ -19,6 +19,12 @@ describe "BigDecimal#to_s" do
@bigdec.to_s.should =~ /^0\.[0-9]*e[0-9]*$/
end
+ it "does not add an exponent for zero values" do
+ BigDecimal("0").to_s.should == "0.0"
+ BigDecimal("+0").to_s.should == "0.0"
+ BigDecimal("-0").to_s.should == "-0.0"
+ end
+
it "takes an optional argument" do
lambda {@bigdec.to_s("F")}.should_not raise_error()
end