-
Notifications
You must be signed in to change notification settings - Fork 605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rand fixes #3182
Rand fixes #3182
Conversation
@@ -52,6 +52,19 @@ | |||
it "returns a float for an range argument where max is < 1" do | |||
rand(0.25..0.75).should be_kind_of(Float) | |||
end | |||
|
|||
it "returns a numeric for an range argument where max is < 1" do | |||
require 'bigdecimal' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want random require
calls in specs. This should either be moved to the top of the file, or the whole test should be moved into its own file.
@brixen Any thoughts on this, is this something we perhaps want in rubysl-bigdecimal instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, Ruby does not have a built-in float-like object. Moving this test into BigDecimal would no longer be testing the actual implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rule to not require standard lib in core lib specs is broken in a few places but those need to be fixed.
The code does not depend on BigDecimal and the specs should not either. The specs should describe the API and protocol (ie which methods are expected and which methods will be used to coerce values).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brixen What would be the best way of testing float-like numbers in core? These bugs are happening because the code eagerly checks for integer-ness instead of float-ness, but I can't reproduce them without a separate Float implementation.
Also in general, is there a good way of detecting integer-ness vs float-ness? Seems like MRI doesn't do a good job (rational often behaves like integers).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fengb your proposed patch adds conditionals for is_a?(Integer)
and respond_to?(:to_f)
. Those cases should be possible to cover with specs that neither need BigDecimal, nor an alternate Float implementation.
Am I missing something else?
@fengb sorry it took so long to get this merged. Thanks for helping! |
Proposed fixes for #3180
Does not completely fix case 3 as there is weird type coercion that goes deeper: #3181