Back to main

QuickCheck Tutorial 10

Summary - Generators

QuickCheck is able to generate random values for each input argument at run time, provided that there is a default/custom generator for that type. The master seed for randomness is the current time.

QuickCheck generates values via the following steps:
1 The master generator is called with 7 arguments:
Arg1 type_desc of the required term
Arg2 SF for the current term
Arg3 a list of all GF
Arg4 a list of all custom generators
Arg5 ouputs a univ of the generated term
Arg6 random number supply input
Arg7 random number supply output
2a QuickCheck searches through the list of custom generators, if there is a custum generator for the current term, then call the custom generator with Arg1, 2, 3, 4, 6, 7. The master generator will return what ever is returned by the custom generator.
2b If QuickCheck fails to locate a custom generator, then it will classify the current term as of type int, char, float, string, discriminated union, and other.
3b1 If it's type int, call rand_int/2 with Arg6 and Arg7
3b2 If it's type char, call rand_char/2 with Arg6 and Arg7
3b3 If it's type float, call rand_float/2 with Arg6 and Arg7
3b4 If it's type string, call rand_string/2 with Arg6 and Arg8
3b5 If it's type discriminated union, call rand_union/6 with Arg1, Arg2, Arg3, Arg4, Arg6, Arg7.
3b6 If it's classified as other, then call rand_function with Arg1, Arg6 and Arg7. Quickcheck will generates the appropriate value if Arg1 is of a function with arity 0 to 10. Otherwise an error will be thrown: "no default generator for this type".