mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	Update to ruby/spec@e81b3cd
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									0f64776745
								
							
						
					
					
						commit
						a28aa80c73
					
				
					 53 changed files with 932 additions and 106 deletions
				
			
		| 
						 | 
				
			
			@ -73,6 +73,14 @@ describe "BigDecimal#add" do
 | 
			
		|||
#    BigDecimal("0.88").add(0.0, 1).should == BigDecimal("0.9")
 | 
			
		||||
#  end
 | 
			
		||||
 | 
			
		||||
  describe "with Object" do
 | 
			
		||||
    it "tries to coerce the other operand to self" do
 | 
			
		||||
      object = mock("Object")
 | 
			
		||||
      object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4])
 | 
			
		||||
      @frac_3.add(object, 1).should == BigDecimal("0.1E16")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "favors the precision specified in the second argument over the global limit" do
 | 
			
		||||
    BigDecimalSpecs.with_limit(1) do
 | 
			
		||||
      BigDecimal('0.888').add(@zero, 3).should == BigDecimal('0.888')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -42,6 +42,14 @@ describe "BigDecimal#div" do
 | 
			
		|||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe "with Object" do
 | 
			
		||||
    it "tries to coerce the other operand to self" do
 | 
			
		||||
      object = mock("Object")
 | 
			
		||||
      object.should_receive(:coerce).with(@one).and_return([@one, @two])
 | 
			
		||||
      @one.div(object).should == @zero
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "raises FloatDomainError if NaN is involved" do
 | 
			
		||||
    lambda { @one.div(@nan) }.should raise_error(FloatDomainError)
 | 
			
		||||
    lambda { @nan.div(@one) }.should raise_error(FloatDomainError)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,7 +9,8 @@ end
 | 
			
		|||
describe "BigDecimal#mult" do
 | 
			
		||||
  before :each do
 | 
			
		||||
    @one = BigDecimal "1"
 | 
			
		||||
    @e3_minus = BigDecimal "3E-20001"
 | 
			
		||||
    @e3_minus = BigDecimal("3E-20001")
 | 
			
		||||
    @e3_plus = BigDecimal("3E20001")
 | 
			
		||||
    @e = BigDecimal "1.00000000000000000000123456789"
 | 
			
		||||
    @tolerance = @e.sub @one, 1000
 | 
			
		||||
    @tolerance2 = BigDecimal "30001E-20005"
 | 
			
		||||
| 
						 | 
				
			
			@ -21,4 +22,11 @@ describe "BigDecimal#mult" do
 | 
			
		|||
    @e3_minus.mult(@one, 1).should be_close(0, @tolerance2)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe "with Object" do
 | 
			
		||||
    it "tries to coerce the other operand to self" do
 | 
			
		||||
      object = mock("Object")
 | 
			
		||||
      object.should_receive(:coerce).with(@e3_minus).and_return([@e3_minus, @e3_plus])
 | 
			
		||||
      @e3_minus.mult(object, 1).should == BigDecimal("9")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,4 +23,12 @@ describe "BigDecimal#*" do
 | 
			
		|||
    (@e3_minus * @e3_minus).should == BigDecimal("9E-40002")
 | 
			
		||||
    (@e * @one).should == @e
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe "with Object" do
 | 
			
		||||
    it "tries to coerce the other operand to self" do
 | 
			
		||||
      object = mock("Object")
 | 
			
		||||
      object.should_receive(:coerce).with(@e3_minus).and_return([@e3_minus, @e3_plus])
 | 
			
		||||
      (@e3_minus * object).should == BigDecimal("9")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,8 @@ describe "BigDecimal#remainder" do
 | 
			
		|||
 | 
			
		||||
  before :each do
 | 
			
		||||
    @zero = BigDecimal("0")
 | 
			
		||||
    @one = BigDecimal("0")
 | 
			
		||||
    @one = BigDecimal("1")
 | 
			
		||||
    @three = BigDecimal("3")
 | 
			
		||||
    @mixed = BigDecimal("1.23456789")
 | 
			
		||||
    @pos_int = BigDecimal("2E5555")
 | 
			
		||||
    @neg_int = BigDecimal("-2E5555")
 | 
			
		||||
| 
						 | 
				
			
			@ -71,9 +72,16 @@ describe "BigDecimal#remainder" do
 | 
			
		|||
  end
 | 
			
		||||
 | 
			
		||||
  it "coerces arguments to BigDecimal if possible" do
 | 
			
		||||
    @one.remainder(2).should == @one
 | 
			
		||||
    @three.remainder(2).should == @one
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe "with Object" do
 | 
			
		||||
    it "tries to coerce the other operand to self" do
 | 
			
		||||
      object = mock("Object")
 | 
			
		||||
      object.should_receive(:coerce).with(@three).and_return([@three, 2])
 | 
			
		||||
      @three.remainder(object).should == @one
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "raises TypeError if the argument cannot be coerced to BigDecimal" do
 | 
			
		||||
    lambda {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -70,6 +70,15 @@ describe :bigdecimal_modulo, shared: true do
 | 
			
		|||
    res.kind_of?(BigDecimal).should == true
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe "with Object" do
 | 
			
		||||
    it "tries to coerce the other operand to self" do
 | 
			
		||||
      bd6543 = BigDecimal("6543.21")
 | 
			
		||||
      object = mock("Object")
 | 
			
		||||
      object.should_receive(:coerce).with(bd6543).and_return([bd6543, 137])
 | 
			
		||||
      bd6543.send(@method, object, *@object).should == BigDecimal("104.21")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "returns NaN if NaN is involved" do
 | 
			
		||||
    @nan.send(@method, @nan).nan?.should == true
 | 
			
		||||
    @nan.send(@method, @one).nan?.should == true
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,6 +29,14 @@ describe :bigdecimal_quo, shared: true do
 | 
			
		|||
    @one.send(@method, BigDecimal('2E-5555'), *@object).should == BigDecimal('0.5E5555')
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe "with Object" do
 | 
			
		||||
    it "tries to coerce the other operand to self" do
 | 
			
		||||
      object = mock("Object")
 | 
			
		||||
      object.should_receive(:coerce).with(@one).and_return([@one, @two])
 | 
			
		||||
      @one.send(@method, object, *@object).should == BigDecimal("0.5")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "returns 0 if divided by Infinity" do
 | 
			
		||||
    @zero.send(@method, @infinity, *@object).should == 0
 | 
			
		||||
    @frac_2.send(@method, @infinity, *@object).should == 0
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,8 @@ describe "BigDecimal#sub" do
 | 
			
		|||
    @one_minus = BigDecimal("-1")
 | 
			
		||||
    @frac_1 = BigDecimal("1E-99999")
 | 
			
		||||
    @frac_2 = BigDecimal("0.9E-99999")
 | 
			
		||||
    @frac_3 = BigDecimal("12345E10")
 | 
			
		||||
    @frac_4 = BigDecimal("98765E10")
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "returns a - b with given precision" do
 | 
			
		||||
| 
						 | 
				
			
			@ -32,6 +34,14 @@ describe "BigDecimal#sub" do
 | 
			
		|||
    @frac_1.sub(@frac_1, 1000000).should == @zero
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe "with Object" do
 | 
			
		||||
    it "tries to coerce the other operand to self" do
 | 
			
		||||
      object = mock("Object")
 | 
			
		||||
      object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4])
 | 
			
		||||
      @frac_3.sub(object, 1).should == BigDecimal("-0.9E15")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  it "returns NaN if NaN is involved" do
 | 
			
		||||
    @one.sub(@nan, 1).nan?.should == true
 | 
			
		||||
    @nan.sub(@one, 1).nan?.should == true
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										42
									
								
								spec/ruby/library/bigdecimal/util_spec.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								spec/ruby/library/bigdecimal/util_spec.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,42 @@
 | 
			
		|||
require_relative '../../spec_helper'
 | 
			
		||||
require 'bigdecimal'
 | 
			
		||||
require 'bigdecimal/util'
 | 
			
		||||
 | 
			
		||||
describe "BigDecimal's util method definitions" do
 | 
			
		||||
  describe "#to_d" do
 | 
			
		||||
    it "should define #to_d on Integer" do
 | 
			
		||||
      42.to_d.should == BigDecimal(42)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "should define #to_d on Float" do
 | 
			
		||||
      0.5.to_d.should == BigDecimal(0.5, Float::DIG)
 | 
			
		||||
      1.234.to_d(2).should == BigDecimal(1.234, 2)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "should define #to_d on String" do
 | 
			
		||||
      "0.5".to_d.should == BigDecimal(0.5, Float::DIG)
 | 
			
		||||
      "45.67 degrees".to_d.should == BigDecimal(45.67, Float::DIG)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "should define #to_d on BigDecimal" do
 | 
			
		||||
      bd = BigDecimal("3.14")
 | 
			
		||||
      bd.to_d.should equal(bd)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "should define #to_d on Rational" do
 | 
			
		||||
      Rational(22, 7).to_d(3).should == BigDecimal(3.14, 3)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    ruby_version_is "2.6" do
 | 
			
		||||
      it "should define #to_d on nil" do
 | 
			
		||||
        nil.to_d.should == BigDecimal(0)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe "#to_digits" do
 | 
			
		||||
    it "should define #to_digits on BigDecimal" do
 | 
			
		||||
      BigDecimal("3.14").to_digits.should == "3.14"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue