PHP Class QCheck\Generator

Based on clojure.test.check.generators.
Afficher le fichier Open project: steos/php-quickcheck Class Usage Examples

Méthodes publiques

Méthode 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

Méthode 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 méthode

creates a generator that produces only alphabetic characters
public static alphaChars ( ) : Generator
Résultat Generator

alphaNumChars() public static méthode

creates a generator that produces alphanumeric characters
public static alphaNumChars ( ) : Generator
Résultat Generator

alphaNumStrings() public static méthode

creates a generator that produces alphanumeric strings
public static alphaNumStrings ( ) : Generator
Résultat Generator

alphaStrings() public static méthode

creates a generator that produces alphabetic strings
public static alphaStrings ( ) : Generator
Résultat Generator

any() public static méthode

public static any ( )

anyPrintable() public static méthode

public static anyPrintable ( )

arraysOf() public static méthode

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

asciiChars() public static méthode

creates a generator that produces only ASCII characters
public static asciiChars ( ) : Generator
Résultat Generator

asciiStrings() public static méthode

creates a generator that produces ASCII strings
public static asciiStrings ( ) : Generator
Résultat Generator

bind() public méthode

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
Résultat Generator

booleans() public static méthode

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

call() public méthode

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

chars() public static méthode

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

choose() public static méthode

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
Résultat Generator

containerTypes() public static méthode

public static containerTypes ( self $innerType )
$innerType self

elements() public static méthode

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
Résultat Generator

fmap() public méthode

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

forAll() public static méthode

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

frequency() public static méthode

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

intRoseTree() public static méthode

public static intRoseTree ( $val )

intoArrays() public méthode

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

ints() public static méthode

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

maps() public static méthode

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
Résultat Generator

mapsFrom() public méthode

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

mapsTo() public méthode

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

mapsWith() public static méthode

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

negInts() public static méthode

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

notEmpty() public méthode

public notEmpty ( $maxTries = 10 )

oneOf() public static méthode

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
Résultat Generator

posInts() public static méthode

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

recursive() public static méthode

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

resize() public méthode

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

samples() public méthode

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

simplePrintableTypes() public static méthode

public static simplePrintableTypes ( )

simpleTypes() public static méthode

public static simpleTypes ( )

sizes() public static méthode

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

strictlyNegInts() public static méthode

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

strictlyPosInts() public static méthode

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

strings() public static méthode

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

suchThat() public méthode

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
Résultat Generator

takeSamples() public méthode

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

tuples() public static méthode

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
Résultat Generator

unit() public static méthode

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