diff options
Diffstat (limited to 'spec/ruby/core/integer/gcd_spec.rb')
| -rw-r--r-- | spec/ruby/core/integer/gcd_spec.rb | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/spec/ruby/core/integer/gcd_spec.rb b/spec/ruby/core/integer/gcd_spec.rb index 69f711d4c5..1fff785927 100644 --- a/spec/ruby/core/integer/gcd_spec.rb +++ b/spec/ruby/core/integer/gcd_spec.rb @@ -7,8 +7,8 @@ describe "Integer#gcd" do end it "returns an Integer" do - 36.gcd(6).should be_kind_of(Integer) - 4.gcd(20981).should be_kind_of(Integer) + 36.gcd(6).should.is_a?(Integer) + 4.gcd(20981).should.is_a?(Integer) end it "returns the greatest common divisor of self and argument" do @@ -33,26 +33,37 @@ describe "Integer#gcd" do it "accepts a Bignum argument" do bignum = 9999**99 - bignum.should be_kind_of(Bignum) + bignum.should.is_a?(Integer) 99.gcd(bignum).should == 99 end it "works if self is a Bignum" do bignum = 9999**99 - bignum.should be_kind_of(Bignum) + bignum.should.is_a?(Integer) bignum.gcd(99).should == 99 end + it "doesn't cause an integer overflow" do + [2 ** (1.size * 8 - 2), 0x8000000000000000].each do |max| + [max - 1, max, max + 1].each do |num| + num.gcd(num).should == num + (-num).gcd(num).should == num + (-num).gcd(-num).should == num + num.gcd(-num).should == num + end + end + end + it "raises an ArgumentError if not given an argument" do - lambda { 12.gcd }.should raise_error(ArgumentError) + -> { 12.gcd }.should.raise(ArgumentError) end it "raises an ArgumentError if given more than one argument" do - lambda { 12.gcd(30, 20) }.should raise_error(ArgumentError) + -> { 12.gcd(30, 20) }.should.raise(ArgumentError) end it "raises a TypeError unless the argument is an Integer" do - lambda { 39.gcd(3.8) }.should raise_error(TypeError) - lambda { 45872.gcd([]) }.should raise_error(TypeError) + -> { 39.gcd(3.8) }.should.raise(TypeError) + -> { 45872.gcd([]) }.should.raise(TypeError) end end |
