The size parameter is used in many functions in quickcheck. But I am having difficulty understanding what it is exactly. What does getSize return?
1 Answers
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
callsg
, passing it the current size as a parameter. For example, to generate natural numbers in the range 0 to size, usesized $ \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 >>=)
.

- 1
- 1

- 45,431
- 5
- 48
- 98
-
If I write a generator for a customized data type, what is its `size`? I have to define it? – sinoTrinity Apr 29 '20 at 00:24
-
@sinoTrinity What data type exactly? Can you edit it into your question? – Joseph Sible-Reinstate Monica Apr 29 '20 at 00:26
-
I'm not asking for a specific data type, but a generic one. – sinoTrinity Apr 29 '20 at 19:07
-
1In `arbitrary`, `size` isn't a value you set; it's a value you get. For fixed-size types like `Maybe`, you ignore it. For variable-sized types like `List`, you make the list have `size` elements. – Joseph Sible-Reinstate Monica Apr 30 '20 at 01:44
-
Yes, I can read/get it, I can also set it w/ `resize`. But what's its initial value and where is it set in the first place? Is the value different for different `arbitrary`s? – sinoTrinity May 08 '20 at 18:45
-
bump. How to create a custom generator for which you can set a size? – The Coding Wombat Feb 16 '22 at 17:19
-
1@TheCodingWombat You can use [`resize`](https://hackage.haskell.org/package/QuickCheck-2.14.2/docs/Test-QuickCheck.html#v:resize) for that, but first double-check that you actually have a good reason for a generator to do so. – Joseph Sible-Reinstate Monica Feb 16 '22 at 17:43