-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Implement Random for BigInt #6687
Conversation
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.
Perhaps the extension should live in src/big/big_int.cr
instead of being directly implemented in src/random.cr
?
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 additions to Random should go in big_int.cr
spec/std/random_spec.cr
Outdated
x.should be >= 0 | ||
x.should be < 2 | ||
|
||
rand(0.to_big_i).should eq(0.to_big_i) |
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.
This contradicts with #6686
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.
Yep, whichever of those gets merged 2nd, will need to be changed
spec/std/random_spec.cr
Outdated
@@ -115,6 +143,12 @@ describe "Random" do | |||
expect_raises ArgumentError, "Invalid range for rand: 1..0" do | |||
rand(1..0) | |||
end | |||
expect_raises ArgumentError, "Invalid range for rand: 1_big_i...1_big_i" do |
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.
1_big_i
isn't a thing. Maybe better use 1.to_big_i
as in code.
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.
Well I didn't make this up, it's just to_s
. But a good idea to change that to also rely on to_s
.
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.
Let's merge if on phase with #6686
Yeah this is ready, as long as there are no merge conflicts |
* Implement Random for BigInt Fixes crystal-lang#5647 * spec typo fix * Move to big_int.cr * Use to_s in spec * Remove special case of zero because it will be removed in crystal-lang#6686
Fixes #5647
cc @iSarCasm @jzakiya