How do I generate a recursive structure with reused objects? #6012
Replies: 3 comments 8 replies
-
|
Yeah, I think everything that's not an "inductive datatype" (aka. tree-like) is gonna be annoying to generate. Objects with circular references are graph-like. One thing you could do is generate random IDs instead of object references directly. And then you replace those IDs with actual objects in a second pass. Unfortunately, I think the only way to produce a circular reference is with mutation. And mutation breaks shrinking, I think. Can you maybe give more details on your use case? Maybe there is something else we can do. |
Beta Was this translation helpful? Give feedback.
-
|
I'd also be interested in figuring out a clean way to do this. I've worked on an OpenAPI (v3) arbitrary that generates arbitrary OpenAPI documents, and I had to use a bunch of hacks to get the document to be "self-referencing". Here's the code for that (although it's not nearly as elegant as @gruhn's ideas). It also uses chaining to get the job done, which is a less than ideal. Would be curious to hear if anyone else has attempted this kind of thing, since it would be great to shrinkable arbitrary (although I'm not sure it's possible). |
Beta Was this translation helpful? Give feedback.
-
|
@TomerAberbach did propose an awesome option in #6040 for As such I came up with an alternate options that will have to be refine but that will allow our users to provide fast-check with a schema of the entities they want and the links they have between each others. The proposed API is visible on #6333. So far many features are missing: reverse-links, ability to constrain links so that they can be exclusive or only refer to next entries to avoid cycles or any other ideas that could make a strategy, shrinking... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been using
fc.letrecto generate recursive structures, which is working well, but I'm wondering how I can generate a recursive object where sometimes objects are reused, and where sometimes those reuses are also circular.Example non-circular reuse:
Example circular reuse:
Beta Was this translation helpful? Give feedback.
All reactions