Home > Software design >  What does the maxSize field describe in Args from Test.QuickCheck?
What does the maxSize field describe in Args from Test.QuickCheck?

Time:12-17

I'm looking at maxSize in Args. its description says: "Size to use for the biggest test cases". But how is the size of test cases determined? I'd rather to ask than to go through the source code:

myArgs :: Args
myArgs = Args{replay=Nothing
             ,maxSuccess=1000
             ,maxDiscardRatio=1
             ,maxSize=1
             ,chatty=False
             ,maxShrinks=0}

So for example if I have an arbitrary of type Gen String and another of type Gen [String], then if maxSize=1 this means that the length of the generated string is 1 and the length of the generated list of String is 1?

CodePudding user response:

If I recall correctly, each Arbitrary instance is free to respect or use the size parameter as it makes sense. For instance, size doesn't make much sense for an Arbitrary for Bool.

Try experimenting with it yourself. For lists, it definitely has an effect like you assume:

Prelude Test.QuickCheck> propList = const True :: [Int] -> Bool

Prelude Test.QuickCheck> verboseCheckWith (Test.QuickCheck.stdArgs { maxSize = 2 }) propList
Passed:
[]

Passed:
[1]

Passed:
[]

Passed:
[0]

Passed:
[]

Passed:
[1]

(I've edited the output to get the point across, because the actual output is, as implied by the function name, verbose.)

CodePudding user response:

According to the outdated manual it means length for lists (note that String is also a list). The documentation does not seem to specify it anywhere for the particular instances.

The size factor in the sized function mentioned in the manual is calculated with the following comment:

-- e.g. with maxSuccess = 250, maxSize = 100, goes like this: -- 0, 1, 2, ..., 99, 0, 1, 2, ..., 99, 0, 2, 4, ..., 98.

Also, looking at the code it limits integral values by bounding them from -size to size.

  • Related