PHP Class QCheck\Generator

Based on clojure.test.check.generators.
Datei anzeigen Open project: steos/php-quickcheck Class Usage Examples

Public Methods

Method Description
alphaChars ( ) : Generator creates a generator that produces only alphabetic characters
alphaNumChars ( ) : Generator creates a generator that produces alphanumeric characters
alphaNumStrings ( ) : Generator creates a generator that produces alphanumeric strings
alphaStrings ( ) : Generator creates a generator that produces alphabetic strings
any ( )
anyPrintable ( )
arraysOf ( self $gen ) : Generator creates a generator that produces arrays whose elements are chosen from $gen.
asciiChars ( ) : Generator creates a generator that produces only ASCII characters
asciiStrings ( ) : Generator creates a generator that produces ASCII strings
bind ( callable $k ) : Generator creates a new generator that passes the result of this generator to the callable $k which should return a new generator.
booleans ( ) : Generator creates a generator that produces true or false. Shrinks to false.
call ( Random $rng, integer $size ) : RoseTree invokes the generator with the given RNG and size
chars ( ) : Generator creates a generator that produces characters from 0-255
choose ( integer $lower, integer $upper ) : Generator creates a generator that returns numbers in the range $lower to $upper, inclusive
containerTypes ( self $innerType )
elements ( ) : Generator creates a generator that randomly chooses from the specified values
fmap ( callable $f ) : Generator maps function f over the values produced by this generator
forAll ( array $args, callable $f )
frequency ( ) : Generator creates a generator that produces values from specified generators based on likelihoods. The likelihood of a generator being chosen is its likelihood divided by the sum of all likelihoods.
intRoseTree ( $val )
intoArrays ( ) : Generator creates a generator that produces arrays whose elements are chosen from this generator.
ints ( ) : Generator creates a generator that returns a positive or negative integer bounded by the generators size parameter.
maps ( self $keygen, self $valgen ) : Generator creates a generator that produces arrays with keys chosen from $keygen and values chosen from $valgen.
mapsFrom ( self $keygen ) : Generator creates a generator that produces arrays with keys chosen from $keygen and values chosen from this generator.
mapsTo ( self $valgen ) : Generator creates a generator that produces arrays with keys chosen from this generator and values chosen from $valgen.
mapsWith ( array $map ) : Generator creates a generator that produces arrays with the same keys as in $map where each corresponding value is chosen from a specified generator.
negInts ( ) : Generator creates a generator that produces negative integers bounded by the generators size parameter.
notEmpty ( $maxTries = 10 )
oneOf ( ) : Generator creates a new generator that randomly chooses a value from the list of provided generators. Shrinks toward earlier generators as well as shrinking the generated value itself.
posInts ( ) : Generator creates a generator that produces positive integers bounded by the generators size parameter.
recursive ( callable $container, self $scalar )
resize ( integer $n ) : Generator creates a new generator based on this generator with size always bound to $n
samples ( integer $maxSize = 100 ) : Generator returns an infinite sequence of random samples from this generator bounded by $maxSize
simplePrintableTypes ( )
simpleTypes ( )
sizes ( $maxSize ) --------------------------------------------------
strictlyNegInts ( ) : Generator creates a generator that produces strictly negative integers bounded by the generators size parameter.
strictlyPosInts ( ) : Generator creates a generator that produces strictly positive integers bounded by the generators size parameter.
strings ( ) : Generator creates a generator that produces strings; may contain unprintable chars
suchThat ( callable $pred, integer $maxTries = 10 ) : Generator creates a new generator that generates values from this generator such that they satisfy callable $pred.
takeSamples ( integer $num = 10 ) : array returns an array of $num random samples from this generator
tuples ( ) : Generator creates a new generator that returns an array whose elements are chosen from the list of given generators. Individual elements shrink according to their generator but the array will never shrink in count.
unit ( mixed $value ) : Generator creates a generator that always returns $value and never shrinks

Private Methods

Method Description
__construct ( callable $gen )
bindGen ( callable $k )
fmapGen ( callable $k )
getArgs ( array $args )
halfs ( $n ) --------------------------------------------------
pureGen ( $value )
randRange ( Random $rng, $lower, $upper )
recursiveHelper ( $container, $scalar, $scalarSize, $childrenSize, $height )
sequence ( Generator[] | Iterator $ms ) : Generator turns a list of generators into a generator of a list
shrinkInt ( $i )
sized ( callable $sizedGen )

Method Details

alphaChars() public static method

creates a generator that produces only alphabetic characters
public static alphaChars ( ) : Generator
return Generator

alphaNumChars() public static method

creates a generator that produces alphanumeric characters
public static alphaNumChars ( ) : Generator
return Generator

alphaNumStrings() public static method

creates a generator that produces alphanumeric strings
public static alphaNumStrings ( ) : Generator
return Generator

alphaStrings() public static method

creates a generator that produces alphabetic strings
public static alphaStrings ( ) : Generator
return Generator

any() public static method

public static any ( )

anyPrintable() public static method

public static anyPrintable ( )

arraysOf() public static method

creates a generator that produces arrays whose elements are chosen from $gen.
public static arraysOf ( self $gen ) : Generator
$gen self
return Generator

asciiChars() public static method

creates a generator that produces only ASCII characters
public static asciiChars ( ) : Generator
return Generator

asciiStrings() public static method

creates a generator that produces ASCII strings
public static asciiStrings ( ) : Generator
return Generator

bind() public method

creates a new generator that passes the result of this generator to the callable $k which should return a new generator.
public bind ( callable $k ) : Generator
$k callable
return Generator

booleans() public static method

creates a generator that produces true or false. Shrinks to false.
public static booleans ( ) : Generator
return Generator

call() public method

invokes the generator with the given RNG and size
public call ( Random $rng, integer $size ) : RoseTree
$rng Random
$size integer
return RoseTree

chars() public static method

creates a generator that produces characters from 0-255
public static chars ( ) : Generator
return Generator

choose() public static method

creates a generator that returns numbers in the range $lower to $upper, inclusive
public static choose ( integer $lower, integer $upper ) : Generator
$lower integer
$upper integer
return Generator

containerTypes() public static method

public static containerTypes ( self $innerType )
$innerType self

elements() public static method

Accepts either a variadic number of args or a single array of values. Example: Gen::elements('foo', 'bar', 'baz') Gen::elements(['foo', 'bar', 'baz'])
public static elements ( ) : Generator
return Generator

fmap() public method

maps function f over the values produced by this generator
public fmap ( callable $f ) : Generator
$f callable
return Generator

forAll() public static method

public static forAll ( array $args, callable $f )
$args array
$f callable

frequency() public static method

Example: Gen::frequency( 5, Gen::ints(), 3, Gen::booleans(), 2, Gen::alphaStrings() )
public static frequency ( ) : Generator
return Generator

intRoseTree() public static method

public static intRoseTree ( $val )

intoArrays() public method

creates a generator that produces arrays whose elements are chosen from this generator.
public intoArrays ( ) : Generator
return Generator

ints() public static method

creates a generator that returns a positive or negative integer bounded by the generators size parameter.
public static ints ( ) : Generator
return Generator

maps() public static method

creates a generator that produces arrays with keys chosen from $keygen and values chosen from $valgen.
public static maps ( self $keygen, self $valgen ) : Generator
$keygen self
$valgen self
return Generator

mapsFrom() public method

creates a generator that produces arrays with keys chosen from $keygen and values chosen from this generator.
public mapsFrom ( self $keygen ) : Generator
$keygen self
return Generator

mapsTo() public method

creates a generator that produces arrays with keys chosen from this generator and values chosen from $valgen.
public mapsTo ( self $valgen ) : Generator
$valgen self
return Generator

mapsWith() public static method

Example: Gen::mapsWith( 'foo' => Gen::booleans(), 'bar' => Gen::ints() )
public static mapsWith ( array $map ) : Generator
$map array
return Generator

negInts() public static method

creates a generator that produces negative integers bounded by the generators size parameter.
public static negInts ( ) : Generator
return Generator

notEmpty() public method

public notEmpty ( $maxTries = 10 )

oneOf() public static method

Accepts either a variadic number of args or a single array of generators. Example: Gen::oneOf(Gen::booleans(), Gen::ints()) Gen::oneOf([Gen::booleans(), Gen::ints()])
public static oneOf ( ) : Generator
return Generator

posInts() public static method

creates a generator that produces positive integers bounded by the generators size parameter.
public static posInts ( ) : Generator
return Generator

recursive() public static method

public static recursive ( callable $container, self $scalar )
$container callable
$scalar self

resize() public method

creates a new generator based on this generator with size always bound to $n
public resize ( integer $n ) : Generator
$n integer
return Generator

samples() public method

returns an infinite sequence of random samples from this generator bounded by $maxSize
public samples ( integer $maxSize = 100 ) : Generator
$maxSize integer
return Generator

simplePrintableTypes() public static method

public static simplePrintableTypes ( )

simpleTypes() public static method

public static simpleTypes ( )

sizes() public static method

--------------------------------------------------
public static sizes ( $maxSize )

strictlyNegInts() public static method

creates a generator that produces strictly negative integers bounded by the generators size parameter.
public static strictlyNegInts ( ) : Generator
return Generator

strictlyPosInts() public static method

creates a generator that produces strictly positive integers bounded by the generators size parameter.
public static strictlyPosInts ( ) : Generator
return Generator

strings() public static method

creates a generator that produces strings; may contain unprintable chars
public static strings ( ) : Generator
return Generator

suchThat() public method

At most $maxTries attempts will be made to generate a value that satisfies the predicate. At every retry the size parameter will be increased. In case of failure an exception will be thrown.
public suchThat ( callable $pred, integer $maxTries = 10 ) : Generator
$pred callable
$maxTries integer
return Generator

takeSamples() public method

returns an array of $num random samples from this generator
public takeSamples ( integer $num = 10 ) : array
$num integer
return array

tuples() public static method

Accepts either a variadic number of args or a single array of generators. Example: Gen::tuples(Gen::booleans(), Gen::ints()) Gen::tuples([Gen::booleans(), Gen::ints()])
public static tuples ( ) : Generator
return Generator

unit() public static method

creates a generator that always returns $value and never shrinks
public static unit ( mixed $value ) : Generator
$value mixed
return Generator