Skip to main content

Composites

Composite arbitraries take other arbitraries as input and assemble them into structured values. An array is built from an arbitrary for its elements, a record is built from arbitraries for each of its fields and so on. There is no "random structure" to speak of, only a shape you describe and a child arbitrary that fills it.

Two concepts recur on every page in this section and are worth learning once:

  • Size control. Most composites accept minLength / maxLength bounds and a size modifier that scales how large generated values tend to be in practice (see size explained).
  • Two-dimensional shrinking. When a test fails on a composite, fast-check shrinks along two axes independently: the structure (it tries shorter arrays, fewer object keys, smaller tuples) and the contents (each surviving element is shrunk by its own arbitrary). This is why counterexamples on nested data tend to collapse cleanly to the minimal offender rather than to an opaque blob.