You must use the forAll function from QuickCheck. It has the following type:
forAll :: (Show a, Testable prop) => Gen a
forAll takes two arguments:
- The generator describes how to create values. Examples of generators are choose , arbitrary , oneof , ...
- The function checks the property for a given input. It should return a value that is an instance of
Testable , for example, another Property , Bool or function.
An example of a nested forAll using select elements and elements:
-- This generates a Property p for all x in the closed interval [1,3] -- The property p in turn generates a property q for all y β [4,5] -- The property q is True if x < y. prop_choose = forAll (choose (1,3)) $ \x -> forAll (elements [4,5]) $ \y -> x < y
For your test property, you can use forAll with a choice for the second and third arguments. For the first argument, QuickCheck has a type Positive a , which can be used to generate arbitrary positive values ββof type a (it has an arbitrary instance when a has Num):
prop_alwayLessThanMaxIdx :: Positive Integer -> Property prop_alwaysLessThanMaxIdx (Positive idx) = forAll (choose (0,1)) $ \r1 -> forAll (choose (0,1)) $ \r2 -> (rndListIndex idx r1 r2) < idx
source share