gentest icon indicating copy to clipboard operation
gentest copied to clipboard

Combinators to modify the size parameter

Open graue opened this issue 11 years ago • 0 comments

Motivation: the invisible size parameter, which ramps up from 1 to 50 (by default, controllable with --max-size) over the course of a test run, controls both array lengths and the magnitude of generated integers. This means it is not possible to, for example, generate short arrays containing large numbers (e.g. 10 integers that are all in the millions), or long arrays containing small numbers (e.g., 100,000 integers between 0 and 10).

To enable this, we need to allow something like:

t.arrayOf(t.scaleSize(5, t.int.nonNegative))

In which scaleSize(mult, gen) would delegate to gen but with the size parameter multiplied by mult.

Reading the size is useful for creating recursive structures, so we should have that too. See "A generator for bounded trees" in this QuickCheck example.

Other implementations (test.check) also have combinators to set the size to a constant amount (not a multiplier), but I am less clear on why this would be useful.

graue avatar Aug 15 '14 16:08 graue