Arbitraries builder based on themselves (through tie
)
type Leaf = number;
type Node = [Tree, Tree];
type Tree = Node | Leaf;
const { tree } = fc.letrec<{ tree: Tree, node: Node, leaf: Leaf }>(tie => ({
tree: fc.oneof({depthSize: 'small'}, tie('leaf'), tie('node')),
node: fc.tuple(tie('tree'), tie('tree')),
leaf: fc.nat()
}));
// tree is 50% of node, 50% of leaf
// the ratio goes in favor of leaves as we go deeper in the tree (thanks to depthSize)
For mutually recursive types
Arbitraries builder based on themselves (through tie
)
For mutually recursive types