0

I want to generate a tree with different node types. For each node type there are different possible combinations of node types that can become children of that node. Any node type may have no children.

recursive-gen essentially forces me to build the tree inside out by starting with a leaf generator that generates a node of any type with no children. The function that creates a generator from a child generator essentially has to generate a desired parent node type and use such-that on the child generator until it has generated the desired child node types. This often leads to runtime errors saying that such-that failed after 10 tries.

Since there is no way to parameterize the child generator from the parent generator, what alternative options are there?

Leon Grapenthin
  • 9,246
  • 24
  • 37

1 Answers1

1

A similar tactic to the such-that could be to generate a full tree with unrestricted children, and then post-process it by filtering out the disallowed children at each level.

The obvious downside is you could end up getting fairly small trees most of the time, as well as doing a lot of throwaway work.

gfredericks
  • 1,312
  • 6
  • 11
  • Do you recommend that over the https://github.com/clojure/test.check/blob/v0.5.8/doc/intro.md#recursive-generators 0.5.8 example? It seems to allow me to build the tree outside-in and do more tuning on the size. If so, why? Also, is there a possibility for a outside-in recursive-gen implementation coming? – Leon Grapenthin Dec 30 '15 at 17:07
  • 1
    No, I think the manual approach you linked to is cleaner at the moment if you can handle the sizing well; `recursive-gen` is actually still pretty bad about sizing, but I had a hard time improving it last time I tried. – gfredericks Dec 30 '15 at 17:10
  • I would love for there to be a better built-in generic recursive generator, but I don't have a concrete plan at the moment. I think this example is an interesting one and it would be nice to have enough control to support it. – gfredericks Dec 30 '15 at 17:12
  • Thanks. I'll try it with the 0.5.8 approach and get back to you on JIRA when if I see a useful way to generalize it fitting this example. – Leon Grapenthin Dec 30 '15 at 17:24