Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
There are still outstanding issues that you left unadressed. But what's more, I realized that the random string generator just produced a long
Str[Normal()...]
2/3 of the time, and the rest it managed to produce an invalid string. These aren't interesting inputs. The entire setup (even in the source language) is just flawed. Basically, what we want are random expressions that are either valid or invalid, but otherwise look similar.For this reason, and to avoid having to go back and forth many more times, I took the liberty of forking my own revision to apply the fixes I deem necessary.
You're free to look over it and comment on it; after all, this is still your translation and you might have issues with changes I made. Otherwise I will approve it at some later time.
I'm not sure how to parse your message. Here's what I typically do:
assert_eq!(actual, expected, "\nYour result (left) did not match the expected output (right) for the input: {input:?})
Would this be an okay asserion message?
Left - actual result, right - expected result. Test failed on string: "{case_str}"
<3
mod preloaded
part. For clarity, I'll just post here what the test setup should look like:struct RegExp
snippet is still in the initial solution. Remove it, and replace it with the statementuse preloaded::RegExp
enum RegExp{
Box::new
, despite saying you're omitting it:impl Display for RegExp
belongs in Preloaded, together with the struct itself.random_regexp
generator, yourNormal
case produces characters in the entire printable range. This includes*
and|
, which is very likely not what you want. Again, just write a constant byte arrayb"abcd...ABCD..."
and sample that randomly (you needrand::seq::SliceRandom
)As before, this needs more fixes. Please have another go at it.
Wow! Thank you for that review and recommendations!
Notes:
mod solution
) can leak to the user. Please move it undermod tests
, and changepub fn _str_to_regex
topub(super) fn...
_
) so test code is easier to review.assert!(...)
and constructing a custom message that displays the input and clearly points out what is expected and what was actually returned by the user. Always test your assertions with a purposefully failing solution. You might find it useful to create a custom testing function that takes an input string, an expected result, and does the comparison and proper assertions in one place, and use that everywhere you are currently callingassert_eq!
.mod preloaded
into the tests section (both sample and full tests), at the very top (outsidemod tests
), but leaveuse preloaded::RegExp
in the initial solution. The reason is that if a user chooses to modify code (e.g. removing the mod statement), then this should only affect their code (it will break), but should not affect test code.use super::RegExp
is exactly what we don't want to rely on in the tests module.Box::new
is ommitted for readability, then go ahead and actually remove all the noisyBox::new
stuff. This should make the structure much more clear at a glance (the necessity for boxing is an implementation detail). After all, the sample tests contain theBox::new
calls, so unfamiliar users should understand how to create recursive structures from that.{:#?}
printing). Readability is valuable, line-count is not.chars().nth()
). I'd recommend turningprintable
(which is a silly name, taken from Python) into a byte slice (b".."
), then usingSliceRandom::choose
length
times:(0..length).map(|_| printable.choose(&mut rng).unwrap() as char).collect()
Because the translation as is contains critical issues, I will reject it. Please feel free to fork it and apply any necessary fixes, so it can be reviewed again.
This comment is hidden because it contains spoiler information about the solution
Why did you used a lamda function?