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

Rust: Enable "rand" feature on the "num" crate #102

Closed
Minoru opened this issue Feb 2, 2021 · 9 comments
Closed

Rust: Enable "rand" feature on the "num" crate #102

Minoru opened this issue Feb 2, 2021 · 9 comments

Comments

@Minoru
Copy link

Minoru commented Feb 2, 2021

Is your feature request related to a problem? Please describe.
I'm translating this kata to Rust, and I need to generate large random integers for testing. The num crate contains a BigUint type which fits my purpose, and even has a RandBigInt trait that generates random numbers — but that trait is only available if the "rand" feature is enabled on the "num" crate, which CodeWars doesn't do.

Describe the solution you'd like
I'd like CodeWars to add the following to their Cargo.toml:

[dependencies.num]
features = [ "rand" ]

Describe alternatives you've considered
It's possible to copy the code from the num crate into each test suite, but doing so for each kata with big numbers would be bothersome.

@Minoru Minoru changed the title Enable "rand" feature on "num" crate Rust: Enable "rand" feature on the "num" crate Feb 2, 2021
@hobovsky
Copy link

hobovsky commented Feb 2, 2021

Potential workaround would be to generate a series of u32 digits and use something what documentation describes as pub fn new(digits: Vec<u32>) -> BigUint or pub fn from_slice(slice: &[u32]) -> BigUint. That's how java generates random BigIntegers. Or generate an array of random bytes and use them to instantiate big int with from_bytes_be or from_bytes_le.

@kazk kazk added this to In Progress in CodeRunner Feb 5, 2021
@kazk kazk moved this from In Progress to To Do in CodeRunner Feb 5, 2021
@kazk kazk moved this from To Do to Next Up in CodeRunner Feb 5, 2021
@kazk
Copy link
Member

kazk commented Feb 5, 2021

I'll wait until rust-num/num-bigint#185 is released.

@kazk kazk added blocked Waiting for something request/package and removed kind/feature-request labels Feb 5, 2021
@kazk kazk removed the blocked Waiting for something label Mar 5, 2021
@kazk kazk self-assigned this Mar 5, 2021
@kazk
Copy link
Member

kazk commented Mar 5, 2021

I'll add Rust 1.50 instead of enabling this in 1.49. I'll also change to stop concatenating the preloaded code and use preloaded.rs. This will minimize the awkwardness, and it'll be easier for users to solve locally.

This will break existing solutions for kata using preloaded because the solution must include mod preloaded; now. But it's better to do this now considering how Rust is getting more and more popular on Codewars. (If this is turns out to be a huge problem, I'll consider letting the runner prepend mod preloaded; to affected solutions, but I'd rather not.)

There are currently 48 Rust kata using preloaded, but it looks like some of them can stop using preloaded. Examples:

  • own random function (we didn't have rand at first)
  • small test helper (can duplicate the code in sample tests)
  • reference solution (should be in submission tests)

@kazk
Copy link
Member

kazk commented Mar 5, 2021

Turns out we can avoid breaking in many kata. See https://github.com/codewars/content-issues/wiki/List-of-Rust-Kata-to-Update

@imjasonmiller can you help?

@imjasonmiller
Copy link

Sure @kazk! I'll have a look at the kata tomorrow, as it's past midnight here.

@kazk
Copy link
Member

kazk commented Mar 7, 2021

Deployed 1.50 having num with rand feature. I haven't updated compatible kata yet.

@kazk kazk closed this as completed Mar 7, 2021
CodeRunner automation moved this from Next Up to Done Mar 7, 2021
@kazk
Copy link
Member

kazk commented Mar 9, 2021

Updated most Rust kata to 1.50. See https://github.com/codewars/content-issues/wiki/List-of-Rust-Kata-to-Update for the remaining.

@imjasonmiller
Copy link

I've been able to edit some, but I think I need to raise an issue in order to unlock editing the others? Some of the test cases are unfortunately locked as well, but this unlocks at 10K, right?

@kazk
Copy link
Member

kazk commented Mar 9, 2021

I think I need to raise an issue in order to unlock editing the others?

Yeah, either issues or suggestions will work. The author or those contributed in the past can edit already, so letting them know with a suggestion comment (mentioning the wiki and what should be done) is a good idea.

Some of the test cases are unfortunately locked as well, but this unlocks at 10K, right?

Yeah.


Thanks again for doing this, I'll try to help as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

4 participants