Skip to content
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

Merged
merged 4 commits into from Apr 6, 2016
Merged

Rand fixes #3182

merged 4 commits into from Apr 6, 2016

Conversation

fengb
Copy link
Contributor

@fengb fengb commented Nov 5, 2014

Proposed fixes for #3180

Does not completely fix case 3 as there is weird type coercion that goes deeper: #3181

@fengb fengb changed the title Rand fixes for https://github.com/rubinius/rubinius/issues/3180 Rand fixes for #3180 Nov 5, 2014
@fengb fengb changed the title Rand fixes for #3180 Rand fixes Nov 5, 2014
@@ -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'
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Member

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).

Copy link
Contributor Author

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).

Copy link
Member

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?

@brixen brixen merged commit 2de8e24 into rubinius:master Apr 6, 2016
brixen added a commit that referenced this pull request Apr 6, 2016
@brixen
Copy link
Member

brixen commented Apr 6, 2016

@fengb sorry it took so long to get this merged. Thanks for helping!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants