clojuretreetest.checkgenerative-testing

test.check generate tree with different node types


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?


Solution

  • 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.