Class RushCheck::Gen
In: rushcheck/gen.rb
Parent: Object

Gen provides functions for generating test instances.

Methods

bind   choose   create   create_by_gen   elements   fmap   forall   frequency   generate   lift_array   new   oneof   promote   rand   resize   sized   unit   value   variant   vector  

Public Class methods

choose is one of primitive generators to create a random Gen object. choose returns a Gen object which generates a random value in the bound. It may useful to implement arbitrary method into your class.

create is one of primitive generators to create a random Gen object. create takes at least a class, and any block to generate object. Then create returns a Gen object. It may useful to implement arbitrary method into your class.

create_gen is one of primitive generators to create a random Gen object. create_gen takes an array of Gen objects, and any block to generate object. Then create_gen returns a Gen object. It may useful to implement arbitrary method into your class.

elements is one of primitive generators to create a random Gen object. elements requires an array and returns a Gen object which generates an object in the array randomly. It may useful to implement arbitrary method into your class.

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.

to initialize Gen object, it requires a block which takes two variables. The first argument of block is assumed as an integer, and the second one is assumed as a random generator of RandomGen.

oneof is /one of/ primitive generators to create a random Gen object. oneof requires an array of Gen objects, and returns a Gen object which choose a Gen object in the array randomly. It may useful to implement arbitrary method into your class.

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.

rand returns a Gen object which generates a random number generator.

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.

vector is one of primitive generators to create a Gen object. vector takes two variables, while the first one should be class, and the second one should be length. vector returns a Gen object which generates an array whose components belongs the given class and given length.

Public Instance methods

bind is a monadic function such as Haskel’s (>>=). bind takes a block which has a variable where is the return value of the Gen object. The block should return a Gen object.

fmap is a categorical function as same in Haskell. fmap requires a block which takes one variable.

forall is a function to create a Gen object. forall requires a block which takes any variables and returns a Property object. Then forall returns a generator of the property.

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.

resize returns another Gen object which resized by the given paramater. resize takes one variable in Integer.

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.

[Validate]