diff options
Diffstat (limited to 'spec/ruby/core/rational/exponent_spec.rb')
| -rw-r--r-- | spec/ruby/core/rational/exponent_spec.rb | 88 |
1 files changed, 43 insertions, 45 deletions
diff --git a/spec/ruby/core/rational/exponent_spec.rb b/spec/ruby/core/rational/exponent_spec.rb index f9fdbcb33e..88b4a43796 100644 --- a/spec/ruby/core/rational/exponent_spec.rb +++ b/spec/ruby/core/rational/exponent_spec.rb @@ -5,20 +5,20 @@ describe "Rational#**" do # Guard against the Mathn library guard -> { !defined?(Math.rsqrt) } do it "returns Rational(1) if the exponent is Rational(0)" do - (Rational(0) ** Rational(0)).should eql(Rational(1)) - (Rational(1) ** Rational(0)).should eql(Rational(1)) - (Rational(3, 4) ** Rational(0)).should eql(Rational(1)) - (Rational(-1) ** Rational(0)).should eql(Rational(1)) - (Rational(-3, 4) ** Rational(0)).should eql(Rational(1)) - (Rational(bignum_value) ** Rational(0)).should eql(Rational(1)) - (Rational(-bignum_value) ** Rational(0)).should eql(Rational(1)) + (Rational(0) ** Rational(0)).should.eql?(Rational(1)) + (Rational(1) ** Rational(0)).should.eql?(Rational(1)) + (Rational(3, 4) ** Rational(0)).should.eql?(Rational(1)) + (Rational(-1) ** Rational(0)).should.eql?(Rational(1)) + (Rational(-3, 4) ** Rational(0)).should.eql?(Rational(1)) + (Rational(bignum_value) ** Rational(0)).should.eql?(Rational(1)) + (Rational(-bignum_value) ** Rational(0)).should.eql?(Rational(1)) end it "returns self raised to the argument as a Rational if the exponent's denominator is 1" do - (Rational(3, 4) ** Rational(1, 1)).should eql(Rational(3, 4)) - (Rational(3, 4) ** Rational(2, 1)).should eql(Rational(9, 16)) - (Rational(3, 4) ** Rational(-1, 1)).should eql(Rational(4, 3)) - (Rational(3, 4) ** Rational(-2, 1)).should eql(Rational(16, 9)) + (Rational(3, 4) ** Rational(1, 1)).should.eql?(Rational(3, 4)) + (Rational(3, 4) ** Rational(2, 1)).should.eql?(Rational(9, 16)) + (Rational(3, 4) ** Rational(-1, 1)).should.eql?(Rational(4, 3)) + (Rational(3, 4) ** Rational(-2, 1)).should.eql?(Rational(16, 9)) end it "returns self raised to the argument as a Float if the exponent's denominator is not 1" do @@ -49,12 +49,12 @@ describe "Rational#**" do # Guard against the Mathn library guard -> { !defined?(Math.rsqrt) } do it "returns Rational(1, 1) when the passed argument is 0" do - (Rational(3, 4) ** 0).should eql(Rational(1, 1)) - (Rational(-3, 4) ** 0).should eql(Rational(1, 1)) - (Rational(3, -4) ** 0).should eql(Rational(1, 1)) + (Rational(3, 4) ** 0).should.eql?(Rational(1, 1)) + (Rational(-3, 4) ** 0).should.eql?(Rational(1, 1)) + (Rational(3, -4) ** 0).should.eql?(Rational(1, 1)) - (Rational(bignum_value, 4) ** 0).should eql(Rational(1, 1)) - (Rational(3, -bignum_value) ** 0).should eql(Rational(1, 1)) + (Rational(bignum_value, 4) ** 0).should.eql?(Rational(1, 1)) + (Rational(3, -bignum_value) ** 0).should.eql?(Rational(1, 1)) end end end @@ -62,26 +62,26 @@ describe "Rational#**" do describe "when passed Bignum" do # #5713 it "returns Rational(0) when self is Rational(0) and the exponent is positive" do - (Rational(0) ** bignum_value).should eql(Rational(0)) + (Rational(0) ** bignum_value).should.eql?(Rational(0)) end it "raises ZeroDivisionError when self is Rational(0) and the exponent is negative" do - -> { Rational(0) ** -bignum_value }.should raise_error(ZeroDivisionError) + -> { Rational(0) ** -bignum_value }.should.raise(ZeroDivisionError) end it "returns Rational(1) when self is Rational(1)" do - (Rational(1) ** bignum_value).should eql(Rational(1)) - (Rational(1) ** -bignum_value).should eql(Rational(1)) + (Rational(1) ** bignum_value).should.eql?(Rational(1)) + (Rational(1) ** -bignum_value).should.eql?(Rational(1)) end it "returns Rational(1) when self is Rational(-1) and the exponent is positive and even" do - (Rational(-1) ** bignum_value(0)).should eql(Rational(1)) - (Rational(-1) ** bignum_value(2)).should eql(Rational(1)) + (Rational(-1) ** bignum_value(0)).should.eql?(Rational(1)) + (Rational(-1) ** bignum_value(2)).should.eql?(Rational(1)) end it "returns Rational(-1) when self is Rational(-1) and the exponent is positive and odd" do - (Rational(-1) ** bignum_value(1)).should eql(Rational(-1)) - (Rational(-1) ** bignum_value(3)).should eql(Rational(-1)) + (Rational(-1) ** bignum_value(1)).should.eql?(Rational(-1)) + (Rational(-1) ** bignum_value(3)).should.eql?(Rational(-1)) end ruby_version_is ""..."3.4" do @@ -96,10 +96,10 @@ describe "Rational#**" do it "returns 0.0 when self is > 1 and the exponent is negative" do -> { - (Rational(2) ** -bignum_value).should eql(0.0) + (Rational(2) ** -bignum_value).should.eql?(0.0) }.should complain(/warning: in a\*\*b, b may be too big/) -> { - (Rational(fixnum_max) ** -bignum_value).should eql(0.0) + (Rational(fixnum_max) ** -bignum_value).should.eql?(0.0) }.should complain(/warning: in a\*\*b, b may be too big/) end end @@ -108,37 +108,37 @@ describe "Rational#**" do it "raises an ArgumentError when self is > 1" do -> { (Rational(2) ** bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") -> { (Rational(fixnum_max) ** bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") end it "raises an ArgumentError when self is > 1 and the exponent is negative" do -> { (Rational(2) ** -bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") -> { (Rational(fixnum_max) ** -bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") end it "raises an ArgumentError when self is < -1" do -> { (Rational(-2) ** bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") -> { (Rational(fixnum_min) ** bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") end it "raises an ArgumentError when self is < -1 and the exponent is negative" do -> { (Rational(-2) ** -bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") -> { (Rational(fixnum_min) ** -bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") end end @@ -159,10 +159,10 @@ describe "Rational#**" do it "returns 0.0 when self is < -1 and the exponent is negative" do -> { - (Rational(-2) ** -bignum_value).should eql(0.0) + (Rational(-2) ** -bignum_value).should.eql?(0.0) }.should complain(/warning: in a\*\*b, b may be too big/) -> { - (Rational(fixnum_min) ** -bignum_value).should eql(0.0) + (Rational(fixnum_min) ** -bignum_value).should.eql?(0.0) }.should complain(/warning: in a\*\*b, b may be too big/) end end @@ -171,7 +171,7 @@ describe "Rational#**" do describe "when passed Float" do it "returns self converted to Float and raised to the passed argument" do - (Rational(3, 1) ** 3.0).should eql(27.0) + (Rational(3, 1) ** 3.0).should.eql?(27.0) (Rational(3, 1) ** 1.5).should be_close(5.19615242270663, TOLERANCE) (Rational(3, 1) ** -1.5).should be_close(0.192450089729875, TOLERANCE) end @@ -213,26 +213,24 @@ describe "Rational#**" do it "raises ZeroDivisionError for Rational(0, 1) passed a negative Integer" do [-1, -4, -9999].each do |exponent| - -> { Rational(0, 1) ** exponent }.should raise_error(ZeroDivisionError, "divided by 0") + -> { Rational(0, 1) ** exponent }.should.raise(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| - -> { Rational(0, 1) ** exponent }.should raise_error(ZeroDivisionError, "divided by 0") + -> { Rational(0, 1) ** exponent }.should.raise(ZeroDivisionError, "divided by 0") end end # #7513 it "raises ZeroDivisionError for Rational(0, 1) passed a negative Rational" do - -> { Rational(0, 1) ** Rational(-3, 2) }.should raise_error(ZeroDivisionError, "divided by 0") + -> { Rational(0, 1) ** Rational(-3, 2) }.should.raise(ZeroDivisionError, "divided by 0") end - platform_is_not :solaris do # See https://github.com/ruby/spec/issues/134 - it "returns Infinity for Rational(0, 1) passed a negative Float" do - [-1.0, -3.0, -3.14].each do |exponent| - (Rational(0, 1) ** exponent).infinite?.should == 1 - end + it "returns Infinity for Rational(0, 1) passed a negative Float" do + [-1.0, -3.0, -3.14].each do |exponent| + (Rational(0, 1) ** exponent).infinite?.should == 1 end end end |
