-
Notifications
You must be signed in to change notification settings - Fork 151
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
Generating a vec of a random length #130
Comments
Oh, I wanted to mention that I could probably use a long chain of |
Non expert opinion:
Yes, but the performance will be very different. They both generate similarly, picking a number between 1 and size - 1 then filling a vec until it has that number of elements. Shrinking is very different. The I built the proptests for cargos resolver, witch involved making an DAG. I don't think I have enough of the context to give concrete advice, in your case. If you can share more about what are the Elements and what are the Nodes, I can try to pass on the advice I received. |
@Eh2406 thank you for answering!
OK, yeah, that's bad. But on the other hand this might actually be necessary, since removing a node from a graph might produce an invalid graph unless any nodes that point to it are also removed.
I'm not at liberty to share the full context here, unfortunately. But here's what I can say:
The actual structure in terms of kinds of nodes and what nodes point to what is defined upfront. If I could generate the vector lengths separately from the actual nodes themselves, I could do something like:
What do you think? (Also, could you link to the proptests you wrote? Thank you 💙) |
The proptest for cargo are in resolve.rs and the generators are in support/resolver.rs. I may be the only person to try and read that code, so suggestions are very welcome. Including "I don't understand line number x, can you add a comment explaining it." Fundamentally the generator has 2 parts, one that builds up the essential structure, and a Most of that may be besides the point as I think your suggestion will work with the proptest::Index for picking the random value. |
Ahh, I didn't know about Index -- looks promising, thanks! |
Yep, once I had Thank you! Should I leave this open as a doc request? Making |
Sorry for not following up on this. I'm going to close the issue itself since the question has been addressed. Do you have any suggestions for how |
Possibly adding a note to https://docs.rs/proptest/0.9.1/proptest/strategy/trait.Strategy.html#method.prop_flat_map, though I do know that the documentation for it is already pretty long. |
Hi~! Thanks for writing this library -- as someone that's used QuickCheck extensively, the Proptest shrinking strategy (with what I think of as "structural shrinking") makes a ton more sense and makes it a pleasure to write :)
I'm trying to figure out exactly how collection strategies work. In particular, for a fixed
size
provided to the generator, what's the difference between:and
Would generation and shrinking still continue to work?
The context is that I need to set up a cyclic graph with multiple kinds of nodes, and wanted to generate the number of elements in each vector of nodes separately from generating the elements themselves.
Thank you 💜
The text was updated successfully, but these errors were encountered: