diff options
Diffstat (limited to 'spec/ruby/core/math')
-rw-r--r-- | spec/ruby/core/math/cos_spec.rb | 26 | ||||
-rw-r--r-- | spec/ruby/core/math/ldexp_spec.rb | 6 | ||||
-rw-r--r-- | spec/ruby/core/math/log2_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/math/sqrt_spec.rb | 4 |
4 files changed, 28 insertions, 10 deletions
diff --git a/spec/ruby/core/math/cos_spec.rb b/spec/ruby/core/math/cos_spec.rb index 3ba7a54c38..006afeb2cc 100644 --- a/spec/ruby/core/math/cos_spec.rb +++ b/spec/ruby/core/math/cos_spec.rb @@ -15,7 +15,6 @@ describe "Math.cos" do Math.cos(2*Math::PI).should be_close(1.0, TOLERANCE) end - it "raises a TypeError unless the argument is Numeric and has #to_f" do -> { Math.cos("test") }.should raise_error(TypeError) end @@ -24,14 +23,23 @@ describe "Math.cos" do Math.cos(nan_value).nan?.should be_true end - it "raises a TypeError if the argument is nil" do - -> { Math.cos(nil) }.should raise_error(TypeError) - end - - it "coerces its argument with #to_f" do - f = mock_numeric('8.2') - f.should_receive(:to_f).and_return(8.2) - Math.cos(f).should == Math.cos(8.2) + describe "coerces its argument with #to_f" do + it "coerces its argument with #to_f" do + f = mock_numeric('8.2') + f.should_receive(:to_f).and_return(8.2) + Math.cos(f).should == Math.cos(8.2) + end + + it "raises a TypeError if the given argument can't be converted to a Float" do + -> { Math.cos(nil) }.should raise_error(TypeError) + -> { Math.cos(:abc) }.should raise_error(TypeError) + end + + it "raises a NoMethodError if the given argument raises a NoMethodError during type coercion to a Float" do + object = mock_numeric('mock-float') + object.should_receive(:to_f).and_raise(NoMethodError) + -> { Math.cos(object) }.should raise_error(NoMethodError) + end end end diff --git a/spec/ruby/core/math/ldexp_spec.rb b/spec/ruby/core/math/ldexp_spec.rb index fb7799cf26..6dcf94a663 100644 --- a/spec/ruby/core/math/ldexp_spec.rb +++ b/spec/ruby/core/math/ldexp_spec.rb @@ -45,6 +45,12 @@ describe "Math.ldexp" do it "accepts any second argument that can be coerced with Integer()" do Math.ldexp(3.23, MathSpecs::Integer.new).should be_close(12.92, TOLERANCE) end + + it "returns correct value that closes to the max value of double type" do + Math.ldexp(0.5122058490966879, 1024).should == 9.207889385574391e+307 + Math.ldexp(0.9999999999999999, 1024).should == 1.7976931348623157e+308 + Math.ldexp(0.99999999999999999, 1024).should == Float::INFINITY + end end describe "Math#ldexp" do diff --git a/spec/ruby/core/math/log2_spec.rb b/spec/ruby/core/math/log2_spec.rb index 1594f2d7af..3d4d41d130 100644 --- a/spec/ruby/core/math/log2_spec.rb +++ b/spec/ruby/core/math/log2_spec.rb @@ -15,7 +15,7 @@ describe "Math.log2" do Math.log2((2**301+45677544234809571)).should == 301.0 end - it "raises an Errno::EDOM if the argument is less than 0" do + it "raises Math::DomainError if the argument is less than 0" do -> { Math.log2(-1e-15) }.should raise_error( Math::DomainError) end diff --git a/spec/ruby/core/math/sqrt_spec.rb b/spec/ruby/core/math/sqrt_spec.rb index 779aea2a0a..918e7c3a17 100644 --- a/spec/ruby/core/math/sqrt_spec.rb +++ b/spec/ruby/core/math/sqrt_spec.rb @@ -27,6 +27,10 @@ describe "Math.sqrt" do it "accepts any argument that can be coerced with Float()" do Math.sqrt(MathSpecs::Float.new).should be_close(1.0, TOLERANCE) end + + it "raises a Math::DomainError when given a negative number" do + -> { Math.sqrt(-1) }.should raise_error(Math::DomainError) + end end describe "Math#sqrt" do |