| Class | RushCheck::Gen |
| In: |
rushcheck/gen.rb
|
| Parent: | Object |
Gen provides functions for generating test instances.
frequency is one of primitive generators to create a random Gen object. frequency requires an array of pairs and returns a Gen object. The first component of pair should be a positive Integer and the second one should be a Gen object. The integer acts as a weight for choosing random Gen object in the array. For example, frequency([[1, Gen.rand], [2, Integer.arbitrary]]) returns the random generator Gen.rand in 33%, while another random generator of Integer (Integer.arbitrary) in 67%.
lift_array is one of primitive generators to create a randam Gen object. lift_array takes an array and a block which has a variable. The block should return a Gen object. lift_array returns a Gen object which generates an array of the result of given block for applying each member of given array.
promote is the function to create a Gen object which generates a procedure (Proc). promote requires a block which takes one variable and the block should be return a Gen object. promote returns a Gen object which generate a new procedure with the given block. It may useful to implement coarbitrary method into your class.
sized is a combinator which the programmer can use to access the size bound. It requires a block which takes a variable as an integer for size. The block should be a function which changes the size of random instances.
unit is a monadic function which equals the return function in the Haskell’s monad. It requires one variable and returns a Gen object which generates the given object.
generate returns the random instance. generates takes two variables, where the first one should be an integer and the second should be the random number generator such as StdGen.
value is a method to get the value of the internal procedure. value takes two variables where the first argument is assumed as an integer and the second one is assumed as a random generator of RandomGen.
variant constructs a generator which transforms the random number seed. variant takes one variable which should be an Integer. variant is needed to generate rundom functions.