diff options
Diffstat (limited to 'spec/ruby/core/integer/shared')
| -rw-r--r-- | spec/ruby/core/integer/shared/abs.rb | 18 | ||||
| -rw-r--r-- | spec/ruby/core/integer/shared/equal.rb | 63 | ||||
| -rw-r--r-- | spec/ruby/core/integer/shared/modulo.rb | 114 | ||||
| -rw-r--r-- | spec/ruby/core/integer/shared/next.rb | 25 |
4 files changed, 0 insertions, 220 deletions
diff --git a/spec/ruby/core/integer/shared/abs.rb b/spec/ruby/core/integer/shared/abs.rb deleted file mode 100644 index 43844c9065..0000000000 --- a/spec/ruby/core/integer/shared/abs.rb +++ /dev/null @@ -1,18 +0,0 @@ -describe :integer_abs, shared: true do - context "fixnum" do - it "returns self's absolute fixnum value" do - { 0 => [0, -0, +0], 2 => [2, -2, +2], 100 => [100, -100, +100] }.each do |key, values| - values.each do |value| - value.send(@method).should == key - end - end - end - end - - context "bignum" do - it "returns the absolute bignum value" do - bignum_value(39).send(@method).should == 18446744073709551655 - (-bignum_value(18)).send(@method).should == 18446744073709551634 - end - end -end diff --git a/spec/ruby/core/integer/shared/equal.rb b/spec/ruby/core/integer/shared/equal.rb deleted file mode 100644 index c621ba3f81..0000000000 --- a/spec/ruby/core/integer/shared/equal.rb +++ /dev/null @@ -1,63 +0,0 @@ -describe :integer_equal, shared: true do - context "fixnum" do - it "returns true if self has the same value as other" do - 1.send(@method, 1).should == true - 9.send(@method, 5).should == false - - # Actually, these call Float#==, Integer#== etc. - 9.send(@method, 9.0).should == true - 9.send(@method, 9.01).should == false - - 10.send(@method, bignum_value).should == false - end - - it "calls 'other == self' if the given argument is not an Integer" do - 1.send(@method, '*').should == false - - obj = mock('one other') - obj.should_receive(:==).any_number_of_times.and_return(false) - 1.send(@method, obj).should == false - - obj = mock('another') - obj.should_receive(:==).any_number_of_times.and_return(true) - 2.send(@method, obj).should == true - end - end - - context "bignum" do - before :each do - @bignum = bignum_value - end - - it "returns true if self has the same value as the given argument" do - @bignum.send(@method, @bignum).should == true - @bignum.send(@method, @bignum.to_f).should == true - - @bignum.send(@method, @bignum + 1).should == false - (@bignum + 1).send(@method, @bignum).should == false - - @bignum.send(@method, 9).should == false - @bignum.send(@method, 9.01).should == false - - @bignum.send(@method, bignum_value(10)).should == false - end - - it "calls 'other == self' if the given argument is not an Integer" do - obj = mock('not integer') - obj.should_receive(:==).and_return(true) - @bignum.send(@method, obj).should == true - end - - it "returns the result of 'other == self' as a boolean" do - obj = mock('not integer') - obj.should_receive(:==).exactly(2).times.and_return("woot", nil) - @bignum.send(@method, obj).should == true - @bignum.send(@method, obj).should == false - end - - it "does not lose precision when comparing with a Float" do - (bignum_value(1).send(@method, bignum_value.to_f)).should == false - (bignum_value.send(@method, bignum_value.to_f)).should == true - end - end -end diff --git a/spec/ruby/core/integer/shared/modulo.rb b/spec/ruby/core/integer/shared/modulo.rb deleted file mode 100644 index d0b5e26ed5..0000000000 --- a/spec/ruby/core/integer/shared/modulo.rb +++ /dev/null @@ -1,114 +0,0 @@ -describe :integer_modulo, shared: true do - context "fixnum" do - it "returns the modulus obtained from dividing self by the given argument" do - # test all possible combinations: - # - integer/double/bignum argument - # - positive/negative argument - # - positive/negative self - # - self greater/smaller than argument - - 13.send(@method, 4).should == 1 - 4.send(@method, 13).should == 4 - - 13.send(@method, 4.0).should == 1 - 4.send(@method, 13.0).should == 4 - - (-200).send(@method, 256).should == 56 - (-1000).send(@method, 512).should == 24 - - (-200).send(@method, -256).should == -200 - (-1000).send(@method, -512).should == -488 - - (200).send(@method, -256).should == -56 - (1000).send(@method, -512).should == -24 - - 13.send(@method, -4.0).should == -3.0 - 4.send(@method, -13.0).should == -9.0 - - -13.send(@method, -4.0).should == -1.0 - -4.send(@method, -13.0).should == -4.0 - - -13.send(@method, 4.0).should == 3.0 - -4.send(@method, 13.0).should == 9.0 - - 1.send(@method, 2.0).should == 1.0 - 200.send(@method, bignum_value).should == 200 - - 4.send(@method, bignum_value(10)).should == 4 - 4.send(@method, -bignum_value(10)).should == -18446744073709551622 - -4.send(@method, bignum_value(10)).should == 18446744073709551622 - -4.send(@method, -bignum_value(10)).should == -4 - end - - it "raises a ZeroDivisionError when the given argument is 0" do - -> { 13.send(@method, 0) }.should.raise(ZeroDivisionError) - -> { 0.send(@method, 0) }.should.raise(ZeroDivisionError) - -> { -10.send(@method, 0) }.should.raise(ZeroDivisionError) - end - - it "raises a ZeroDivisionError when the given argument is 0 and a Float" do - -> { 0.send(@method, 0.0) }.should.raise(ZeroDivisionError) - -> { 10.send(@method, 0.0) }.should.raise(ZeroDivisionError) - -> { -10.send(@method, 0.0) }.should.raise(ZeroDivisionError) - end - - it "raises a TypeError when given a non-Integer" do - -> { - (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10) - 13.send(@method, obj) - }.should.raise(TypeError) - -> { 13.send(@method, "10") }.should.raise(TypeError) - -> { 13.send(@method, :symbol) }.should.raise(TypeError) - end - end - - context "bignum" do - before :each do - @bignum = bignum_value(10) - end - - it "returns the modulus obtained from dividing self by the given argument" do - # test all possible combinations: - # - integer/double/bignum argument - # - positive/negative argument - # - positive/negative self - # - self greater/smaller than argument - - @bignum.send(@method, 5).should == 1 - @bignum.send(@method, -5).should == -4 - (-@bignum).send(@method, 5).should == 4 - (-@bignum).send(@method, -5).should == -1 - - @bignum.send(@method, 2.22).should be_close(1.5603603603605034, TOLERANCE) - @bignum.send(@method, -2.22).should be_close(-0.6596396396394968, TOLERANCE) - (-@bignum).send(@method, 2.22).should be_close(0.6596396396394968, TOLERANCE) - (-@bignum).send(@method, -2.22).should be_close(-1.5603603603605034, TOLERANCE) - - @bignum.send(@method, @bignum + 10).should == 18446744073709551626 - @bignum.send(@method, -(@bignum + 10)).should == -10 - (-@bignum).send(@method, @bignum + 10).should == 10 - (-@bignum).send(@method, -(@bignum + 10)).should == -18446744073709551626 - - (@bignum + 10).send(@method, @bignum).should == 10 - (@bignum + 10).send(@method, -@bignum).should == -18446744073709551616 - (-(@bignum + 10)).send(@method, @bignum).should == 18446744073709551616 - (-(@bignum + 10)).send(@method, -@bignum).should == -10 - end - - it "raises a ZeroDivisionError when the given argument is 0" do - -> { @bignum.send(@method, 0) }.should.raise(ZeroDivisionError) - -> { (-@bignum).send(@method, 0) }.should.raise(ZeroDivisionError) - end - - it "raises a ZeroDivisionError when the given argument is 0 and a Float" do - -> { @bignum.send(@method, 0.0) }.should.raise(ZeroDivisionError) - -> { -@bignum.send(@method, 0.0) }.should.raise(ZeroDivisionError) - end - - it "raises a TypeError when given a non-Integer" do - -> { @bignum.send(@method, mock('10')) }.should.raise(TypeError) - -> { @bignum.send(@method, "10") }.should.raise(TypeError) - -> { @bignum.send(@method, :symbol) }.should.raise(TypeError) - end - end -end diff --git a/spec/ruby/core/integer/shared/next.rb b/spec/ruby/core/integer/shared/next.rb deleted file mode 100644 index 85b83d6965..0000000000 --- a/spec/ruby/core/integer/shared/next.rb +++ /dev/null @@ -1,25 +0,0 @@ -describe :integer_next, shared: true do - it "returns the next larger positive Fixnum" do - 2.send(@method).should == 3 - end - - it "returns the next larger negative Fixnum" do - (-2).send(@method).should == -1 - end - - it "returns the next larger positive Bignum" do - bignum_value.send(@method).should == bignum_value(1) - end - - it "returns the next larger negative Bignum" do - (-bignum_value(1)).send(@method).should == -bignum_value - end - - it "overflows a Fixnum to a Bignum" do - fixnum_max.send(@method).should == fixnum_max + 1 - end - - it "underflows a Bignum to a Fixnum" do - (fixnum_min - 1).send(@method).should == fixnum_min - end -end |
