Skip to main content

recursive-gen

function

clojure.test.check.generators/recursive-gen

(recursive-gen [container-gen-fn scalar-gen])
This is a helper for writing recursive (tree-shaped) generators. The first argument should be a function that takes a generator as an argument, and produces another generator that 'contains' that generator. The vector function in this namespace is a simple example. The second argument is a scalar generator, like boolean. For example, to produce a tree of booleans: (gen/recursive-gen gen/vector gen/boolean) Vectors or maps either recurring or containing booleans or integers: (gen/recursive-gen (fn [inner] (gen/one-of [(gen/vector inner) (gen/map inner inner)])) (gen/one-of [gen/boolean gen/small-integer])) Note that raw scalar values will be generated as well. To prevent this, you can wrap the returned generator with the function passed as the first arg, e.g.: (gen/vector (gen/recursive-gen gen/vector gen/boolean))

No examples yet. Be the first to add one!