Repository navigation
Conversation
| @@ -1,39 +0,0 @@ | |||
| require File.expand_path('../../../spec_helper', __FILE__) | |||
|
|
|||
| describe "Fixnum#coerce when given a Fixnum" do | |||
There was a problem hiding this comment.
There is actually Integer#coerce though:
[1] pry(main)> 3.method :coerce
=> #<Method: Integer#coerce>So I think this should be moved to core/integer/coerce_spec.rb
| it_behaves_like :integer_arithmetic_exception_in_coerce, :/ | ||
| ruby_version_is '2.4' do | ||
| describe "Integer#/" do | ||
| it_behaves_like :integer_arithmetic_exception_in_coerce, :/ |
There was a problem hiding this comment.
Can the guards not be part of the shared example?
There was a problem hiding this comment.
By having describe "Integer#/" I think it's OK to mean it's Fixnum#/ + Bignum#/ behavior in Ruby 2.3 and before.
No need to separate those specs, as I meant in #578.
There was a problem hiding this comment.
No need to separate those specs, as I meant in #578.
@eregon Do you mean we need to "adopt" Bignum specs as well?
Please correct me if I misunderstood you. I would like to copy/paste (and revise) all Fixnum/Bignum specs to Integer specs with ruby version guard "2.4" and add ruby version guard ""..."2.4" for existing Fixnum/Bignum specs.
There was a problem hiding this comment.
Yes, really move (and merge) core/fixnum/* and core/bignum/* to core/integer and rename descriptions to Integer#some_method.
So no extra version guards.
The version guards are not needed and not worth the trouble just for classifying methods differently.
I think duplicating the specs would be bad.
And making them shared specs would make them needlessly complicated.
Please share your thoughts if you disagree.
Maybe it's better to wait 2.2 and 2.3 become unsupported, so then it's really clear there should no longer be core/{fixnum,bignum} specs.
I'm proposing to do that already now since anyway behaviorally it is compatible, and the new unified Integer has a nicer structure than separate "small/big integers" specs.
There was a problem hiding this comment.
@eregon FYI There are following minor differences:
Fixnum#hash(as well asInteger#hash) is implemented inKernelFixnum#coerceis implemented inNumericFixnum#eql?(as well asInteger#eql?) is implemented inNumeric
I am OK with moving specs and quite finished it
There was a problem hiding this comment.
Fixnum#coerceis implemented inNumeric
It's in Integer in 2.5 I think:
> 3.method :coerce
=> #<Method: Integer#coerce>| @@ -0,0 +1,44 @@ | |||
| require File.expand_path('../../../spec_helper', __FILE__) | |||
There was a problem hiding this comment.
Seems this file went to the wrong place 😉
|
@eregon Done |
|
|
||
| @bignum.div(21 ).should == 439208192231179804 | ||
| @bignum.div(21.0).should == 439208192231179776 | ||
| end |
There was a problem hiding this comment.
I'm not sure, the Numeric#div rdoc says:
Implementation from Numeric
------------------------------------------------------------------------------
num.div(numeric) -> integer
------------------------------------------------------------------------------
Uses / to perform division, then converts the result to an integer.
Numeric does not define the / operator; this is left to subclasses.
And if indeed it goes through Float then it loses precision:
> 9223372036854775896/21.0
=> 4.392081922311798e+17And the Integer#div rdoc is fairly imprecise:
Implementation from Integer
------------------------------------------------------------------------------
int.div(numeric) -> integer
------------------------------------------------------------------------------
Performs integer division: returns the integer result of dividing int
by numeric.
The implementation is pretty simple:
https://github.com/ruby/ruby/blob/3a887648fe75c022c3f445e5943525226f15e3d0/numeric.c#L571-L588
It calls / then floor.
That would be a good spec and clarify the behavior.
Might still be worth asking on MRI's tracker for clarification though.
| it "raises a TypeError if other is zero and not a Float" do | ||
| lambda { @bignum.send(@method, 0) }.should raise_error(TypeError, /nil is not a symbol nor a string/) | ||
| end | ||
| end |
There was a problem hiding this comment.
again it's very strange behaviour
There was a problem hiding this comment.
This example is not in a shared spec, so @method is probably nil?
| ruby_version_is "2.5" do | ||
| it_behaves_like :integer_arithmetic_coerce_not_rescue, :/ | ||
| end | ||
| end |
There was a problem hiding this comment.
Why did you extract the version guards outside of the shared spec in this commit?
It seems to make usages of the shared spec more verbose and fragile.
Are they problematic or unclear somehow?
There was a problem hiding this comment.
@eregon looks like I misunderstood your previous comment:
Can the guards not be part of the shared example?
There are minor pros and cons so if you want I will revert this change
| lambda { 1.coerce(1..4) }.should raise_error(TypeError) | ||
| lambda { 1.coerce(:test) }.should raise_error(TypeError) | ||
| end | ||
| end |
There was a problem hiding this comment.
This commit seems to remove many specs.
Are they duplicate or so?
There was a problem hiding this comment.
@eregon
Fixnum#coerce in Ruby 2.3 is implemented in Numeric class
irb(main):002:0> 1.method(:coerce).owner
=> NumericSo I just merged them with Numeric#coerce specs. And yes - there was some duplication.
|
@eregon done |
Issue #578
So now we have following methods implemented in
Bignum(Ruby 2.3) but not implemented (and inherited fromNumeric/Kernel) inInteger(Ruby 2.4):#hash,#eql?,#dup,zero?By convention we should test them in Numeric/Kernel so I don't include them to
Integerspecs.