aboutsummaryrefslogtreecommitdiffstats
path: root/spec/rubyspec/library/bigdecimal/split_spec.rb
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-07 12:04:49 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-07 12:04:49 +0000
commita3736e97a6ca517c2cd7d3d93a8f2ef86e39e5b5 (patch)
tree9eef7f720314ebaff56845a74e203770e62284e4 /spec/rubyspec/library/bigdecimal/split_spec.rb
parent52df1d0d3370919711c0577aaa42d1a864709885 (diff)
downloadruby-a3736e97a6ca517c2cd7d3d93a8f2ef86e39e5b5.tar.gz
Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers. * .gitignore: track changes under spec. * spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec. These files can therefore be updated like any other file in MRI. Instructions are provided in spec/README. [Feature #13156] [ruby-core:79246] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/rubyspec/library/bigdecimal/split_spec.rb')
-rw-r--r--spec/rubyspec/library/bigdecimal/split_spec.rb88
1 files changed, 88 insertions, 0 deletions
diff --git a/spec/rubyspec/library/bigdecimal/split_spec.rb b/spec/rubyspec/library/bigdecimal/split_spec.rb
new file mode 100644
index 0000000000..e2ba955a3b
--- /dev/null
+++ b/spec/rubyspec/library/bigdecimal/split_spec.rb
@@ -0,0 +1,88 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'bigdecimal'
+
+describe "BigDecimal#split" do
+
+ before :each do
+ @arr = BigDecimal("0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043E1").split
+ @arr_neg = BigDecimal("-0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043E1").split
+ @digits = "922337203685477580810101333333333333333333333333333"
+ @arr_big = BigDecimal("00#{@digits}000").split
+ @arr_big_neg = BigDecimal("-00#{@digits}000").split
+ @huge = BigDecimal('100000000000000000000000000000000000000000001E90000000').split
+
+ @infinity = BigDecimal("Infinity")
+ @infinity_neg = BigDecimal("-Infinity")
+ @nan = BigDecimal("NaN")
+ @zero = BigDecimal("0")
+ @zero_neg = BigDecimal("-0")
+ end
+
+ it "splits BigDecimal in an array with four values" do
+ @arr.size.should == 4
+ end
+
+ it "first value: 1 for numbers > 0" do
+ @arr[0].should == 1
+ @arr_big[0].should == 1
+ @zero.split[0].should == 1
+ @huge[0].should == 1
+ BigDecimal("+0").split[0].should == 1
+ BigDecimal("1E400").split[0].should == 1
+ @infinity.split[0].should == 1
+ end
+
+ it "first value: -1 for numbers < 0" do
+ @arr_neg[0].should == -1
+ @arr_big_neg[0].should == -1
+ @zero_neg.split[0].should == -1
+ BigDecimal("-1E400").split[0].should == -1
+ @infinity_neg.split[0].should == -1
+ end
+
+ it "first value: 0 if BigDecimal is NaN" do
+ BigDecimal("NaN").split[0].should == 0
+ end
+
+ it "second value: a string with the significant digits" do
+ string = "314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
+ @arr[1].should == string
+ @arr_big[1].should == @digits
+ @arr_big_neg[1].should == @digits
+ @huge[1].should == "100000000000000000000000000000000000000000001"
+ @infinity.split[1].should == @infinity.to_s
+ @nan.split[1].should == @nan.to_s
+ @infinity_neg.split[1].should == @infinity.to_s
+ @zero.split[1].should == "0"
+ BigDecimal("-0").split[1].should == "0"
+ end
+
+ it "third value: the base (currently always ten)" do
+ @arr[2].should == 10
+ @arr_neg[2].should == 10
+ @arr_big[2].should == 10
+ @arr_big_neg[2].should == 10
+ @huge[2].should == 10
+ @infinity.split[2].should == 10
+ @nan.split[2].should == 10
+ @infinity_neg.split[2].should == 10
+ @zero.split[2].should == 10
+ @zero_neg.split[2].should == 10
+ end
+
+ it "fourth value: the exponent" do
+ @arr[3].should == 1
+ @arr_neg[3].should == 1
+ @arr_big[3].should == 54
+ @arr_big_neg[3].should == 54
+ @huge[3].should == 90000045
+ @infinity.split[3].should == 0
+ @nan.split[3].should == 0
+ @infinity_neg.split[3].should == 0
+ @zero.split[3].should == 0
+ @zero_neg.split[3].should == 0
+ end
+
+end
+
+