diff options
Diffstat (limited to 'spec/ruby/library/bigdecimal')
-rw-r--r-- | spec/ruby/library/bigdecimal/BigDecimal_spec.rb | 15 | ||||
-rw-r--r-- | spec/ruby/library/bigdecimal/gt_spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/library/bigdecimal/gte_spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/library/bigdecimal/inspect_spec.rb | 34 | ||||
-rw-r--r-- | spec/ruby/library/bigdecimal/lt_spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/library/bigdecimal/lte_spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/library/bigdecimal/round_spec.rb | 242 | ||||
-rw-r--r-- | spec/ruby/library/bigdecimal/to_s_spec.rb | 12 |
8 files changed, 172 insertions, 195 deletions
diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb index 03f0c0adfd..2312a4e910 100644 --- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb +++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb @@ -58,18 +58,9 @@ describe "Kernel#BigDecimal" do end end - ruby_version_is ""..."2.4" do - it "treats invalid strings as 0.0" do - BigDecimal("ruby").should == BigDecimal("0.0") - BigDecimal(" \t\n \r-\t\t\tInfinity \n").should == BigDecimal("0.0") - end - end - - ruby_version_is "2.4" do - it "raises ArgumentError for invalid strings" do - lambda { BigDecimal("ruby") }.should raise_error(ArgumentError) - lambda { BigDecimal(" \t\n \r-\t\t\tInfinity \n") }.should raise_error(ArgumentError) - end + it "raises ArgumentError for invalid strings" do + lambda { BigDecimal("ruby") }.should raise_error(ArgumentError) + lambda { BigDecimal(" \t\n \r-\t\t\tInfinity \n") }.should raise_error(ArgumentError) end it "allows omitting the integer part" do diff --git a/spec/ruby/library/bigdecimal/gt_spec.rb b/spec/ruby/library/bigdecimal/gt_spec.rb index c815aa0353..8ebb631cb8 100644 --- a/spec/ruby/library/bigdecimal/gt_spec.rb +++ b/spec/ruby/library/bigdecimal/gt_spec.rb @@ -68,15 +68,13 @@ describe "BigDecimal#>" do (@infinity_neg > @infinity).should == false end - ruby_bug "#13674", ""..."2.4" do - it "properly handles Float infinity values" do - @values.each { |val| - (val > @float_infinity).should == false - (@float_infinity > val).should == true - (val > @float_infinity_neg).should == true - (@float_infinity_neg > val).should == false - } - end + it "properly handles Float infinity values" do + @values.each { |val| + (val > @float_infinity).should == false + (@float_infinity > val).should == true + (val > @float_infinity_neg).should == true + (@float_infinity_neg > val).should == false + } end it "properly handles NaN values" do diff --git a/spec/ruby/library/bigdecimal/gte_spec.rb b/spec/ruby/library/bigdecimal/gte_spec.rb index 14534eec80..6b0b7f41e9 100644 --- a/spec/ruby/library/bigdecimal/gte_spec.rb +++ b/spec/ruby/library/bigdecimal/gte_spec.rb @@ -72,15 +72,13 @@ describe "BigDecimal#>=" do (@infinity_neg >= @infinity).should == false end - ruby_bug "#13674", ""..."2.4" do - it "properly handles Float infinity values" do - @values.each { |val| - (val >= @float_infinity).should == false - (@float_infinity >= val).should == true - (val >= @float_infinity_neg).should == true - (@float_infinity_neg >= val).should == false - } - end + it "properly handles Float infinity values" do + @values.each { |val| + (val >= @float_infinity).should == false + (@float_infinity >= val).should == true + (val >= @float_infinity_neg).should == true + (@float_infinity_neg >= val).should == false + } end it "properly handles NaN values" do diff --git a/spec/ruby/library/bigdecimal/inspect_spec.rb b/spec/ruby/library/bigdecimal/inspect_spec.rb index 7e1a8297e2..cd2f1a3cd4 100644 --- a/spec/ruby/library/bigdecimal/inspect_spec.rb +++ b/spec/ruby/library/bigdecimal/inspect_spec.rb @@ -11,37 +11,7 @@ describe "BigDecimal#inspect" do @bigdec.inspect.kind_of?(String).should == true end - ruby_version_is ""..."2.4" do - it "returns String starting with #" do - @bigdec.inspect[0].should == ?# - end - - it "encloses information in angle brackets" do - @bigdec.inspect.should =~ /^.<.*>$/ - end - - it "is comma separated list of three items" do - @bigdec.inspect.should =~ /...*,.*,.*/ - end - - it "value after first comma is value as string" do - @bigdec.inspect.split(",")[1].should == "\'0.12345678E4\'" - end - - it "last part is number of significant digits" do - signific_string = "#{@bigdec.precs[0]}(#{@bigdec.precs[1]})" - @bigdec.inspect.split(",")[2].should == signific_string + ">" - end - - it "looks like this" do - regex = /^\#\<BigDecimal\:.*,'0\.12345678E4',[0-9]+\([0-9]+\)>$/ - @bigdec.inspect.should =~ regex - end - end - - ruby_version_is "2.4" do - it "looks like this" do - @bigdec.inspect.should == "0.12345678e4" - end + it "looks like this" do + @bigdec.inspect.should == "0.12345678e4" end end diff --git a/spec/ruby/library/bigdecimal/lt_spec.rb b/spec/ruby/library/bigdecimal/lt_spec.rb index 8cf92fedd2..1894daf17f 100644 --- a/spec/ruby/library/bigdecimal/lt_spec.rb +++ b/spec/ruby/library/bigdecimal/lt_spec.rb @@ -66,15 +66,13 @@ describe "BigDecimal#<" do (@infinity_neg < @infinity).should == true end - ruby_bug "#13674", ""..."2.4" do - it "properly handles Float infinity values" do - @values.each { |val| - (val < @float_infinity).should == true - (@float_infinity < val).should == false - (val < @float_infinity_neg).should == false - (@float_infinity_neg < val).should == true - } - end + it "properly handles Float infinity values" do + @values.each { |val| + (val < @float_infinity).should == true + (@float_infinity < val).should == false + (val < @float_infinity_neg).should == false + (@float_infinity_neg < val).should == true + } end it "properly handles NaN values" do diff --git a/spec/ruby/library/bigdecimal/lte_spec.rb b/spec/ruby/library/bigdecimal/lte_spec.rb index eff6547369..56d3caa3b1 100644 --- a/spec/ruby/library/bigdecimal/lte_spec.rb +++ b/spec/ruby/library/bigdecimal/lte_spec.rb @@ -72,15 +72,13 @@ describe "BigDecimal#<=" do (@infinity_neg <= @infinity).should == true end - ruby_bug "#13674", ""..."2.4" do - it "properly handles Float infinity values" do - @values.each { |val| - (val <= @float_infinity).should == true - (@float_infinity <= val).should == false - (val <= @float_infinity_neg).should == false - (@float_infinity_neg <= val).should == true - } - end + it "properly handles Float infinity values" do + @values.each { |val| + (val <= @float_infinity).should == true + (@float_infinity <= val).should == false + (val <= @float_infinity_neg).should == false + (@float_infinity_neg <= val).should == true + } end it "properly handles NaN values" do diff --git a/spec/ruby/library/bigdecimal/round_spec.rb b/spec/ruby/library/bigdecimal/round_spec.rb index 07b96acb2b..467e2c5563 100644 --- a/spec/ruby/library/bigdecimal/round_spec.rb +++ b/spec/ruby/library/bigdecimal/round_spec.rb @@ -62,129 +62,157 @@ describe "BigDecimal#round" do @n2_49.round(0).should == @neg_two end - describe "BigDecimal::ROUND_UP" do - it "rounds values away from zero" do - @p1_50.round(0, BigDecimal::ROUND_UP).should == @two - @p1_51.round(0, BigDecimal::ROUND_UP).should == @two - @p1_49.round(0, BigDecimal::ROUND_UP).should == @two - @n1_50.round(0, BigDecimal::ROUND_UP).should == @neg_two - @n1_51.round(0, BigDecimal::ROUND_UP).should == @neg_two - @n1_49.round(0, BigDecimal::ROUND_UP).should == @neg_two - - @p2_50.round(0, BigDecimal::ROUND_UP).should == @three - @p2_51.round(0, BigDecimal::ROUND_UP).should == @three - @p2_49.round(0, BigDecimal::ROUND_UP).should == @three - @n2_50.round(0, BigDecimal::ROUND_UP).should == @neg_three - @n2_51.round(0, BigDecimal::ROUND_UP).should == @neg_three - @n2_49.round(0, BigDecimal::ROUND_UP).should == @neg_three + ["BigDecimal::ROUND_UP", ":up"].each do |way| + describe way do + it "rounds values away from zero" do + mode = eval(way) + + @p1_50.round(0, mode).should == @two + @p1_51.round(0, mode).should == @two + @p1_49.round(0, mode).should == @two + @n1_50.round(0, mode).should == @neg_two + @n1_51.round(0, mode).should == @neg_two + @n1_49.round(0, mode).should == @neg_two + + @p2_50.round(0, mode).should == @three + @p2_51.round(0, mode).should == @three + @p2_49.round(0, mode).should == @three + @n2_50.round(0, mode).should == @neg_three + @n2_51.round(0, mode).should == @neg_three + @n2_49.round(0, mode).should == @neg_three + end end end - describe "BigDecimal::ROUND_DOWN" do - it "rounds values towards zero" do - @p1_50.round(0, BigDecimal::ROUND_DOWN).should == @one - @p1_51.round(0, BigDecimal::ROUND_DOWN).should == @one - @p1_49.round(0, BigDecimal::ROUND_DOWN).should == @one - @n1_50.round(0, BigDecimal::ROUND_DOWN).should == @neg_one - @n1_51.round(0, BigDecimal::ROUND_DOWN).should == @neg_one - @n1_49.round(0, BigDecimal::ROUND_DOWN).should == @neg_one - - @p2_50.round(0, BigDecimal::ROUND_DOWN).should == @two - @p2_51.round(0, BigDecimal::ROUND_DOWN).should == @two - @p2_49.round(0, BigDecimal::ROUND_DOWN).should == @two - @n2_50.round(0, BigDecimal::ROUND_DOWN).should == @neg_two - @n2_51.round(0, BigDecimal::ROUND_DOWN).should == @neg_two - @n2_49.round(0, BigDecimal::ROUND_DOWN).should == @neg_two + ["BigDecimal::ROUND_DOWN", ":down", ":truncate"].each do |way| + describe way do + it "rounds values towards zero" do + mode = eval(way) + + @p1_50.round(0, mode).should == @one + @p1_51.round(0, mode).should == @one + @p1_49.round(0, mode).should == @one + @n1_50.round(0, mode).should == @neg_one + @n1_51.round(0, mode).should == @neg_one + @n1_49.round(0, mode).should == @neg_one + + @p2_50.round(0, mode).should == @two + @p2_51.round(0, mode).should == @two + @p2_49.round(0, mode).should == @two + @n2_50.round(0, mode).should == @neg_two + @n2_51.round(0, mode).should == @neg_two + @n2_49.round(0, mode).should == @neg_two + end end end - describe "BigDecimal::ROUND_HALF_UP" do - it "rounds values >= 5 up, otherwise down" do - @p1_50.round(0, BigDecimal::ROUND_HALF_UP).should == @two - @p1_51.round(0, BigDecimal::ROUND_HALF_UP).should == @two - @p1_49.round(0, BigDecimal::ROUND_HALF_UP).should == @one - @n1_50.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_two - @n1_51.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_two - @n1_49.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_one - - @p2_50.round(0, BigDecimal::ROUND_HALF_UP).should == @three - @p2_51.round(0, BigDecimal::ROUND_HALF_UP).should == @three - @p2_49.round(0, BigDecimal::ROUND_HALF_UP).should == @two - @n2_50.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_three - @n2_51.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_three - @n2_49.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_two + ["BigDecimal::ROUND_HALF_UP", ":half_up", ":default"].each do |way| + describe way do + it "rounds values >= 5 up, otherwise down" do + mode = eval(way) + + @p1_50.round(0, mode).should == @two + @p1_51.round(0, mode).should == @two + @p1_49.round(0, mode).should == @one + @n1_50.round(0, mode).should == @neg_two + @n1_51.round(0, mode).should == @neg_two + @n1_49.round(0, mode).should == @neg_one + + @p2_50.round(0, mode).should == @three + @p2_51.round(0, mode).should == @three + @p2_49.round(0, mode).should == @two + @n2_50.round(0, mode).should == @neg_three + @n2_51.round(0, mode).should == @neg_three + @n2_49.round(0, mode).should == @neg_two + end end end - describe "BigDecimal::ROUND_HALF_DOWN" do - it "rounds values > 5 up, otherwise down" do - @p1_50.round(0, BigDecimal::ROUND_HALF_DOWN).should == @one - @p1_51.round(0, BigDecimal::ROUND_HALF_DOWN).should == @two - @p1_49.round(0, BigDecimal::ROUND_HALF_DOWN).should == @one - @n1_50.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_one - @n1_51.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_two - @n1_49.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_one - - @p2_50.round(0, BigDecimal::ROUND_HALF_DOWN).should == @two - @p2_51.round(0, BigDecimal::ROUND_HALF_DOWN).should == @three - @p2_49.round(0, BigDecimal::ROUND_HALF_DOWN).should == @two - @n2_50.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_two - @n2_51.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_three - @n2_49.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_two + ["BigDecimal::ROUND_HALF_DOWN", ":half_down"].each do |way| + describe way do + it "rounds values > 5 up, otherwise down" do + mode = eval(way) + + @p1_50.round(0, mode).should == @one + @p1_51.round(0, mode).should == @two + @p1_49.round(0, mode).should == @one + @n1_50.round(0, mode).should == @neg_one + @n1_51.round(0, mode).should == @neg_two + @n1_49.round(0, mode).should == @neg_one + + @p2_50.round(0, mode).should == @two + @p2_51.round(0, mode).should == @three + @p2_49.round(0, mode).should == @two + @n2_50.round(0, mode).should == @neg_two + @n2_51.round(0, mode).should == @neg_three + @n2_49.round(0, mode).should == @neg_two + end end end - describe "BigDecimal::ROUND_CEILING" do - it "rounds values towards +infinity" do - @p1_50.round(0, BigDecimal::ROUND_CEILING).should == @two - @p1_51.round(0, BigDecimal::ROUND_CEILING).should == @two - @p1_49.round(0, BigDecimal::ROUND_CEILING).should == @two - @n1_50.round(0, BigDecimal::ROUND_CEILING).should == @neg_one - @n1_51.round(0, BigDecimal::ROUND_CEILING).should == @neg_one - @n1_49.round(0, BigDecimal::ROUND_CEILING).should == @neg_one - - @p2_50.round(0, BigDecimal::ROUND_CEILING).should == @three - @p2_51.round(0, BigDecimal::ROUND_CEILING).should == @three - @p2_49.round(0, BigDecimal::ROUND_CEILING).should == @three - @n2_50.round(0, BigDecimal::ROUND_CEILING).should == @neg_two - @n2_51.round(0, BigDecimal::ROUND_CEILING).should == @neg_two - @n2_49.round(0, BigDecimal::ROUND_CEILING).should == @neg_two + ["BigDecimal::ROUND_CEILING", ":ceiling", ":ceil"].each do |way| + describe way do + it "rounds values towards +infinity" do + mode = eval(way) + + @p1_50.round(0, mode).should == @two + @p1_51.round(0, mode).should == @two + @p1_49.round(0, mode).should == @two + @n1_50.round(0, mode).should == @neg_one + @n1_51.round(0, mode).should == @neg_one + @n1_49.round(0, mode).should == @neg_one + + @p2_50.round(0, mode).should == @three + @p2_51.round(0, mode).should == @three + @p2_49.round(0, mode).should == @three + @n2_50.round(0, mode).should == @neg_two + @n2_51.round(0, mode).should == @neg_two + @n2_49.round(0, mode).should == @neg_two + end end end - describe "BigDecimal::ROUND_FLOOR" do - it "rounds values towards -infinity" do - @p1_50.round(0, BigDecimal::ROUND_FLOOR).should == @one - @p1_51.round(0, BigDecimal::ROUND_FLOOR).should == @one - @p1_49.round(0, BigDecimal::ROUND_FLOOR).should == @one - @n1_50.round(0, BigDecimal::ROUND_FLOOR).should == @neg_two - @n1_51.round(0, BigDecimal::ROUND_FLOOR).should == @neg_two - @n1_49.round(0, BigDecimal::ROUND_FLOOR).should == @neg_two - - @p2_50.round(0, BigDecimal::ROUND_FLOOR).should == @two - @p2_51.round(0, BigDecimal::ROUND_FLOOR).should == @two - @p2_49.round(0, BigDecimal::ROUND_FLOOR).should == @two - @n2_50.round(0, BigDecimal::ROUND_FLOOR).should == @neg_three - @n2_51.round(0, BigDecimal::ROUND_FLOOR).should == @neg_three - @n2_49.round(0, BigDecimal::ROUND_FLOOR).should == @neg_three + ["BigDecimal::ROUND_FLOOR", ":floor"].each do |way| + describe way do + it "rounds values towards -infinity" do + mode = eval(way) + + @p1_50.round(0, mode).should == @one + @p1_51.round(0, mode).should == @one + @p1_49.round(0, mode).should == @one + @n1_50.round(0, mode).should == @neg_two + @n1_51.round(0, mode).should == @neg_two + @n1_49.round(0, mode).should == @neg_two + + @p2_50.round(0, mode).should == @two + @p2_51.round(0, mode).should == @two + @p2_49.round(0, mode).should == @two + @n2_50.round(0, mode).should == @neg_three + @n2_51.round(0, mode).should == @neg_three + @n2_49.round(0, mode).should == @neg_three + end end end - describe "BigDecimal::ROUND_HALF_EVEN" do - it "rounds values > 5 up, < 5 down and == 5 towards even neighbor" do - @p1_50.round(0, BigDecimal::ROUND_HALF_EVEN).should == @two - @p1_51.round(0, BigDecimal::ROUND_HALF_EVEN).should == @two - @p1_49.round(0, BigDecimal::ROUND_HALF_EVEN).should == @one - @n1_50.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_two - @n1_51.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_two - @n1_49.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_one - - @p2_50.round(0, BigDecimal::ROUND_HALF_EVEN).should == @two - @p2_51.round(0, BigDecimal::ROUND_HALF_EVEN).should == @three - @p2_49.round(0, BigDecimal::ROUND_HALF_EVEN).should == @two - @n2_50.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_two - @n2_51.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_three - @n2_49.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_two + ["BigDecimal::ROUND_HALF_EVEN", ":half_even", ":banker"].each do |way| + describe way do + it "rounds values > 5 up, < 5 down and == 5 towards even neighbor" do + mode = eval(way) + + @p1_50.round(0, mode).should == @two + @p1_51.round(0, mode).should == @two + @p1_49.round(0, mode).should == @one + @n1_50.round(0, mode).should == @neg_two + @n1_51.round(0, mode).should == @neg_two + @n1_49.round(0, mode).should == @neg_one + + @p2_50.round(0, mode).should == @two + @p2_51.round(0, mode).should == @three + @p2_49.round(0, mode).should == @two + @n2_50.round(0, mode).should == @neg_two + @n2_51.round(0, mode).should == @neg_three + @n2_49.round(0, mode).should == @neg_two + end end end @@ -199,4 +227,8 @@ describe "BigDecimal#round" do lambda { BigDecimal('Infinity').round(2) }.should_not raise_error(FloatDomainError) lambda { BigDecimal('-Infinity').round(2) }.should_not raise_error(FloatDomainError) end + + it "raise for a non-existent round mode" do + lambda { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode") + end end diff --git a/spec/ruby/library/bigdecimal/to_s_spec.rb b/spec/ruby/library/bigdecimal/to_s_spec.rb index 75741c5050..247db1a5d2 100644 --- a/spec/ruby/library/bigdecimal/to_s_spec.rb +++ b/spec/ruby/library/bigdecimal/to_s_spec.rb @@ -15,16 +15,8 @@ describe "BigDecimal#to_s" do @bigneg.to_s.kind_of?(String).should == true end - ruby_version_is ''...'2.4' do - it "the default format looks like 0.xxxxEnn" do - @bigdec.to_s.should =~ /^0\.[0-9]*E[0-9]*$/ - end - end - - ruby_version_is '2.4' do - it "the default format looks like 0.xxxxenn" do - @bigdec.to_s.should =~ /^0\.[0-9]*e[0-9]*$/ - end + it "the default format looks like 0.xxxxenn" do + @bigdec.to_s.should =~ /^0\.[0-9]*e[0-9]*$/ end it "takes an optional argument" do |