mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@875a09e
This commit is contained in:
parent
a06301b103
commit
5c276e1cc9
1247 changed files with 5316 additions and 5028 deletions
|
@ -80,24 +80,24 @@ describe :kernel_Rational, shared: true do
|
|||
end
|
||||
|
||||
it "raises a RangeError if the imaginary part is not 0" do
|
||||
lambda { Rational(Complex(1, 2)) }.should raise_error(RangeError)
|
||||
-> { Rational(Complex(1, 2)) }.should raise_error(RangeError)
|
||||
end
|
||||
end
|
||||
|
||||
it "raises a TypeError if the first argument is nil" do
|
||||
lambda { Rational(nil) }.should raise_error(TypeError)
|
||||
-> { Rational(nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the second argument is nil" do
|
||||
lambda { Rational(1, nil) }.should raise_error(TypeError)
|
||||
-> { Rational(1, nil) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the first argument is a Symbol" do
|
||||
lambda { Rational(:sym) }.should raise_error(TypeError)
|
||||
-> { Rational(:sym) }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
it "raises a TypeError if the second argument is a Symbol" do
|
||||
lambda { Rational(1, :sym) }.should raise_error(TypeError)
|
||||
-> { Rational(1, :sym) }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
require 'bigdecimal'
|
||||
|
||||
describe :rational_coerce, shared: true do
|
||||
it "returns the passed argument, self as Float, when given a Float" do
|
||||
result = Rational(3, 4).coerce(1.0)
|
||||
|
@ -18,4 +20,10 @@ describe :rational_coerce, shared: true do
|
|||
it "returns [argument, self] when given a Rational" do
|
||||
Rational(3, 7).coerce(Rational(9, 2)).should == [Rational(9, 2), Rational(3, 7)]
|
||||
end
|
||||
|
||||
it "raises an error when passed a BigDecimal" do
|
||||
-> {
|
||||
Rational(500, 3).coerce(BigDecimal('166.666666666'))
|
||||
}.should raise_error(TypeError, /BigDecimal can't be coerced into Rational/)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,11 +7,11 @@ describe :rational_div_rat, shared: true do
|
|||
end
|
||||
|
||||
it "raises a ZeroDivisionError when the argument has a numerator of 0" do
|
||||
lambda { Rational(3, 4).div(Rational(0, 3)) }.should raise_error(ZeroDivisionError)
|
||||
-> { Rational(3, 4).div(Rational(0, 3)) }.should raise_error(ZeroDivisionError)
|
||||
end
|
||||
|
||||
it "raises a ZeroDivisionError when the argument has a numerator of 0.0" do
|
||||
lambda { Rational(3, 4).div(Rational(0.0, 3)) }.should raise_error(ZeroDivisionError)
|
||||
-> { Rational(3, 4).div(Rational(0.0, 3)) }.should raise_error(ZeroDivisionError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -23,7 +23,7 @@ describe :rational_div_float, shared: true do
|
|||
end
|
||||
|
||||
it "raises a ZeroDivisionError when the argument is 0.0" do
|
||||
lambda { Rational(3, 4).div(0.0) }.should raise_error(ZeroDivisionError)
|
||||
-> { Rational(3, 4).div(0.0) }.should raise_error(ZeroDivisionError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -34,7 +34,7 @@ describe :rational_div_int, shared: true do
|
|||
end
|
||||
|
||||
it "raises a ZeroDivisionError when the argument is 0" do
|
||||
lambda { Rational(3, 4).div(0) }.should raise_error(ZeroDivisionError)
|
||||
-> { Rational(3, 4).div(0) }.should raise_error(ZeroDivisionError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -44,11 +44,11 @@ describe :rational_div, shared: true do
|
|||
end
|
||||
|
||||
it "raises an ArgumentError if passed more than one argument" do
|
||||
lambda { Rational(3, 4).div(2,3) }.should raise_error(ArgumentError)
|
||||
-> { Rational(3, 4).div(2,3) }.should raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
# See http://redmine.ruby-lang.org/issues/show/1648
|
||||
it "raises a TypeError if passed a non-numeric argument" do
|
||||
lambda { Rational(3, 4).div([]) }.should raise_error(TypeError)
|
||||
-> { Rational(3, 4).div([]) }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ describe :rational_divide_rat, shared: true do
|
|||
end
|
||||
|
||||
it "raises a ZeroDivisionError when passed a Rational with a numerator of 0" do
|
||||
lambda { Rational(3, 4).send(@method, Rational(0, 1)) }.should raise_error(ZeroDivisionError)
|
||||
-> { Rational(3, 4).send(@method, Rational(0, 1)) }.should raise_error(ZeroDivisionError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -22,7 +22,7 @@ describe :rational_divide_int, shared: true do
|
|||
end
|
||||
|
||||
it "raises a ZeroDivisionError when passed 0" do
|
||||
lambda { Rational(3, 4).send(@method, 0) }.should raise_error(ZeroDivisionError)
|
||||
-> { Rational(3, 4).send(@method, 0) }.should raise_error(ZeroDivisionError)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ describe :rational_divmod_rat, shared: true do
|
|||
end
|
||||
|
||||
it "raises a ZeroDivisonError when passed a Rational with a numerator of 0" do
|
||||
lambda { Rational(7, 4).divmod(Rational(0, 3)) }.should raise_error(ZeroDivisionError)
|
||||
-> { Rational(7, 4).divmod(Rational(0, 3)) }.should raise_error(ZeroDivisionError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -23,7 +23,7 @@ describe :rational_divmod_int, shared: true do
|
|||
end
|
||||
|
||||
it "raises a ZeroDivisionError when passed 0" do
|
||||
lambda { Rational(7, 4).divmod(0) }.should raise_error(ZeroDivisionError)
|
||||
-> { Rational(7, 4).divmod(0) }.should raise_error(ZeroDivisionError)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -37,6 +37,6 @@ describe :rational_divmod_float, shared: true do
|
|||
end
|
||||
|
||||
it "raises a ZeroDivisionError when passed 0" do
|
||||
lambda { Rational(7, 4).divmod(0.0) }.should raise_error(ZeroDivisionError)
|
||||
-> { Rational(7, 4).divmod(0.0) }.should raise_error(ZeroDivisionError)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -66,7 +66,7 @@ describe :rational_exponent, shared: true do
|
|||
end
|
||||
|
||||
it "raises ZeroDivisionError when self is Rational(0) and the exponent is negative" do
|
||||
lambda { Rational(0) ** -bignum_value }.should raise_error(ZeroDivisionError)
|
||||
-> { Rational(0) ** -bignum_value }.should raise_error(ZeroDivisionError)
|
||||
end
|
||||
|
||||
it "returns Rational(1) when self is Rational(1)" do
|
||||
|
@ -153,19 +153,19 @@ describe :rational_exponent, shared: true do
|
|||
|
||||
it "raises ZeroDivisionError for Rational(0, 1) passed a negative Integer" do
|
||||
[-1, -4, -9999].each do |exponent|
|
||||
lambda { Rational(0, 1) ** exponent }.should raise_error(ZeroDivisionError, "divided by 0")
|
||||
-> { Rational(0, 1) ** exponent }.should raise_error(ZeroDivisionError, "divided by 0")
|
||||
end
|
||||
end
|
||||
|
||||
it "raises ZeroDivisionError for Rational(0, 1) passed a negative Rational with denominator 1" do
|
||||
[Rational(-1, 1), Rational(-3, 1)].each do |exponent|
|
||||
lambda { Rational(0, 1) ** exponent }.should raise_error(ZeroDivisionError, "divided by 0")
|
||||
-> { Rational(0, 1) ** exponent }.should raise_error(ZeroDivisionError, "divided by 0")
|
||||
end
|
||||
end
|
||||
|
||||
# #7513
|
||||
it "raises ZeroDivisionError for Rational(0, 1) passed a negative Rational" do
|
||||
lambda { Rational(0, 1) ** Rational(-3, 2) }.should raise_error(ZeroDivisionError, "divided by 0")
|
||||
-> { Rational(0, 1) ** Rational(-3, 2) }.should raise_error(ZeroDivisionError, "divided by 0")
|
||||
end
|
||||
|
||||
platform_is_not :solaris do # See https://github.com/ruby/spec/issues/134
|
||||
|
|
|
@ -22,21 +22,21 @@ describe :rational_modulo, shared: true do
|
|||
end
|
||||
|
||||
it "raises ZeroDivisionError on zero denominator" do
|
||||
lambda {
|
||||
-> {
|
||||
Rational(3, 5).send(@method, Rational(0, 1))
|
||||
}.should raise_error(ZeroDivisionError)
|
||||
|
||||
lambda {
|
||||
-> {
|
||||
Rational(0, 1).send(@method, Rational(0, 1))
|
||||
}.should raise_error(ZeroDivisionError)
|
||||
|
||||
lambda {
|
||||
-> {
|
||||
Rational(3, 5).send(@method, 0)
|
||||
}.should raise_error(ZeroDivisionError)
|
||||
end
|
||||
|
||||
it "raises a ZeroDivisionError when the argument is 0.0" do
|
||||
lambda {
|
||||
-> {
|
||||
Rational(3, 5).send(@method, 0.0)
|
||||
}.should raise_error(ZeroDivisionError)
|
||||
end
|
||||
|
|
|
@ -100,7 +100,7 @@ describe :rational_round, shared: true do
|
|||
end
|
||||
|
||||
it "raise for a non-existent round mode" do
|
||||
lambda { Rational(10, 4).round(half: :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode: nonsense")
|
||||
-> { Rational(10, 4).round(half: :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode: nonsense")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue