5

The size parameter is used in many functions in quickcheck. But I am having difficulty understanding what it is exactly. What does getSize return?

sinoTrinity
  • 1,125
  • 2
  • 15
  • 27

1 Answers1

2

From the manual:

Test data generators have an implicit size parameter; quickCheck begins by generating small test cases, and gradually increases the size as testing progresses. Different test data generators interpret the size parameter in different ways: some ignore it, while the list generator, for example, interprets it as an upper bound on the length of generated lists. You are free to use it as you wish to control your own test data generators.

You can obtain the value of the size parameter using

sized :: (Int -> Gen a) -> Gen a

sized g calls g, passing it the current size as a parameter. For example, to generate natural numbers in the range 0 to size, use

sized $ \n -> choose (0, n)

The purpose of size control is to ensure that test cases are large enough to reveal errors, while remaining small enough to test fast.

And getSize is just another way to get that size parameter. Note that getSize is equivalent to sized pure, and sized is equivalent to (getSize >>=).

Community
  • 1
  • 1