API

Function Index

Stability

The entries written on this page are automatically generated and DO NOT represent the currently supported API surface. PropCheck.jl is currently in a 0.x release; feel free to use anything you can find here, but know that (for now) only symbols that are exported are expected to stick around (they too may change, but I don't expect the underlying functionality to vanish entirely).

Nevertheless, I don't really expect things to change too much - the package is already complicated as is.

Function reference

Base.Iterators.mapMethod
map(f, ::Tree)

Maps the function f over the nodes of the given Tree, returning a new true.

The subtrees of the tree returned by map are guaranteed to be unique.

source
Base.filterMethod
filter(p, i::AbstractIntegrated[, trim=false]) -> AbstractIntegrated

Filters i lazily such that all elements contained fulfill the predicate p, i.e. all elements for which p is false are removed.

trim controls whether subtrees are removed completely when the root doesn't fulfill the predicate or whether only that root should be skipped, still trying to shrink its subtrees. This trades performance (less shrinks to check) for quality (fewer/less diverse shrink values tried).

source
Base.filterMethod
filter(pred, ::Tree, trim=false)

Filters the given Tree by applying the predicate pred to each root.

Filtering is done lazily for subtrees.

trim controls whether subtrees that don't match the predicate should be pruned entirely, or only their roots should be removed from the resulting Tree. If trim is true, subtrees of subtrees that don't match the predicate are moved to the parent.

source
Base.mapMethod
map(f, i::AbstractIntegrated) -> AbstractIntegrated

Maps f lazily over all elements in i, producing an AbstractIntegrated generating the mapped values.

source
PropCheck.arrayMethod
PropCheck.array(genSize::AbstractIntegrated, genA::AbstractIntegrated{Tree{T}}) where T

A utility function for creating an integrated shrinker producing Array{T, N}, with its size controlled by the tuple generated from genLen and its elements created by genA. If genSize produces an integer instead of a tuple of integers, this function will produce a Vector instead.

This is generally the best way to create a shrinkable array, as it takes shrinking both size & elements into account, irrespective of shrinking order.

FiniteIntegrated

Using a FiniteIntegrated{T} for the elements will cause the array to have Union{Nothing, T} as its eltype, because they may stop generating T at any point!

source
PropCheck.assembleMethod
assemble(::T, sign::I, expo::I, frac::I) where {I, T <: Union{Float16, Float32, Float64}} -> T

Assembles sign, expo and frac arguments into the floating point number of type T it represents. sizeof(T) must match sizeof(I).

source
PropCheck.bind!Method
bind!(ibr::IntegratedBoundedRec{T}, ai::AbstractIntegrated{T})

Binds the given AbstractIntegrated to ibr, such that it will be called for generation when generate(ibr) is called.

This needs to be called to allow mutual recursion during generation.

source
PropCheck.checkMethod
check(p, i::AbstractIntegrated[, rng::AbstractRNG=Random.default_rng()];
         ntests::Int=PropCheck.numTest[], show_initial=true, transform=identity)

Checks whether the boolean predicate function p returns true for all values generated by i.

Keyword arguments:

  • ntests: How many values to generate & check
  • show_initial: Whether to show the initial failing example in the printed @info message
  • transform: an optional transforming function to apply before returning a failure case
    • This can be used to make a given value, like a floating point NaN, easier to inspect & reproduce
source
PropCheck.extentMethod
extent(::ExtentIntegrated) -> Tuple{T,T} where T

Gives a tuple of the upper & lower bound of this ExtentIntegrated.

source
PropCheck.freezeMethod
freeze(::T) where T <: AbstractIntegrated -> T

"Freezes" an AbstractIntegrated by returning a new object that has a generate method, and can be wrapped in a new integrated shrinker.

source
PropCheck.iconstMethod
iconst(x) -> AbstractIntegrated

A convenience constructor for creating an integrated shrinker.

Trees created by this do not shrink, and generate on the returned AbstractIntegrated will always produce x.

source
PropCheck.ifloatMethod
ifloat(::T) where T <: Union{Float16, Float32, Float64}

An integrated shrinker producing floating point values, except NaNs and Infs.

NaN & Inf

There are multiple valid bitpatterns for both NaN- and Inf-like values. This shrinker is guaranteed not to produce any of them of its own volition. However, functions running on the values produced by this shrinker may still result in NaN or Inf to be produced. For example, if this shrinker produces a 0.0 and that number is passed to x -> 1.0/x, you'll still get a Inf. This can be important for mapping over this shrinker.

source
PropCheck.ifloatinfnanMethod
ifloatinfnan(::Type{T}) where T <: Union{Float16, Float32, Float64}

An integrated shrinker producing nothing but valid NaNs and Infs.

Implemented more efficiently than naive combining of ifloatnan and ifloatinf.

source
PropCheck.inegintMethod
inegint(::Type{T}[, shrink=shrink]) where T <: Union{Int8, Int16, Int32, Int64, Int128}

An integrated shrinker producing negative values of type T.

source
PropCheck.iposintMethod
iposint(::Type{T}[, shrink=shrink]) where T <: Union{Int8, Int16, Int32, Int64, Int128}

An integrated shrinker producing positive values of type T.

source
PropCheck.isampleFunction
isample(x[, shrink=shrink]) -> AbstractIntegrated

A convenience constructor for creating an integrated shrinker.

Trees created by this shrink according to shrink, and generate on the returned Integrated will always produce an element of the collection x.

x needs to be indexable.

source
PropCheck.isampleFunction
isample(x::AbstractRange[, shrink=shrinkTowards(first(x))]) -> AbstractIntegrated

A convenience constructor for creating an integrated shrinker.

Trees created by this shrink towards the first element of the range by default.

source
PropCheck.iuniqueMethod
iunique(x::Vector, shrink=shrink) -> AbstractIntegrated

A convenience constructor for creating an integrated shrinker.

This shrinker produces all unique values of x before producing a value it has produced before. The produced trees shrink according to shrink.

source
PropCheck.ivalMethod
ival(x::T[, shrink=shrink]) -> AbstractIntegrated

A convenience constructor for creating integrated shrinkers, generating their values from a starting value.

Trees created by this function will always initially have x at their root, as well as shrink according to shrink.

source
PropCheck.nanHashFunction
nanHash(x[, h=zero(UInt)])

Produces a hash for values, with special consideration for NaNs, ensuring distinct bitpatterns in NaN produce different hashes.

source
PropCheck.shrinkTowardsFunction
shrinkTowards(to::T) -> (x::T -> T[...])

Constructs a shrinker function that shrinks given values towards to.

source
PropCheck.strFunction
str(len::ExtentIntegrated[, alphabet::AbstractIntegrated])

Generates a string using the given genLen as a generator for the length. The default alphabet is typemin(Char):""[1], which is all representable Char values.

source
PropCheck.tearMethod
tear(x::T) where T <: Union{Float16, Float32, Float64} -> Tuple{I, I, I}

Returns the sign, exponent and fractional parts of a floating point number. The returned tuple consists of three unsigned integer types I of the same bitwidth as T.

source
PropCheck.tupleMethod
tuple(genLen::AbstractIntegrated, genA::AbstractIntegrated)

Generates a tuple of a generated length, using the elements produced by genA.

FiniteIntegrated

Using a FiniteIntegrated{T} will cause the tuple to have Union{Nothing, T} as its eltype, because they may stop generating T at any point!

Type stability

Due to the length produced by genLen not being known until runtime, this function is by its very nature type unstable. Consider using interleave and a fixed number of known generators instead.

source
PropCheck.unfoldMethod
unfold(f, root)

Unfolds root into a Tree, by applying f to each root to create subtrees.

root is the new root of the returned Tree. f must return an iterable object with eltype egal to typeof(root).

source
PropCheck.vectorMethod
PropCheck.vector(genLen::ExtentIntegrated, genA::AbstractIntegrated{Tree{T}}) where T

A utility function for creating an integrated shrinker producing Vector{T}, with its length controlled by the number generated from genLen and its elements created by genA.

This is generally the best way to create a shrinkable vector, as it takes shrinking both length & elements into account, irrespective of shrinking order.

FiniteIntegrated

Using a FiniteIntegrated{T} for the elements will cause the vector to have Union{Nothing, T} as its eltype in the general case, because they may stop generating T at any point!

source
PropCheck.FlattenType
Flatten{Eltype}

An iterator like Base.flatten, except with inferrable eltype. Requires the given iterators to have the same eltype.

Type mismatches

The given Eltype is used to assert the return type; a type mismatch there will throw.

source
PropCheck.IntegratedType
Integrated{T} <: InfiniteIntegrated{T}

A naive integrated shrinker, only providing extremely basic functionality for generating and shrinking Trees. Default fallback if no other, more specialized type exists.

Pending Redesign

This type is likely going to be redesigned in the future. Methods constructing it are not stable, and may be removed at any point.

source
PropCheck.IntegratedBoundedRecType
IntegratedBoundedRec{T}(maxrec)
IntegratedBoundedRec(maxrec, ai::AbstractIntegrated)
IntegratedBoundedRec{T} <: AbstractIntegrated{T}

An AbstractIntegrated for allowing mutual recursion between two AbstractIntegrated. Used by inserting as a shim into one AbstractIntegrated, creating a second AbstractIntegrated and setting the second one as bind!(::IntegratedBoundedRec, ::AbstractIntegrated) of the shim afterwards.

Mutual recursion

This type is for allowing mutual recursion between two (or more) different integrated shrinkers. Selfrecursion could also be done through this, but is likely to be more efficient when implemented explicitly (or bounded through other means), due to the need for type instability on self recursion as a result of how this type is implemented.

Experimental

This integrated shrinker is very experimental, and some uses still don't work correctly. If possible, try to avoid the kind of mutually recursive generation this would enable.

source
PropCheck.IntegratedChainType
ChainIntegrated(is::AbstractIntegrated...)
ChainIntegrated{Eltype, N, Is, Finite} where {Eltype, N,
                                        Is <: NTuple{N, <:AbstractIntegrated}, Finite} <: AbstractIntegrated{Eltype}

An integrated shrinker chaining together a number of given integrated shrinkers, producing the values they generate one after another.

All except the last argument must have some finite length, meaning the integrated shrinker must subtype FiniteIntegrated. Only the last integrated shrinker is allowed to be only <: InfiniteIntegrated.

The values produced by this integrated shrinker shrink according to the shrinking function given to the shrinker that originally produce them.

The Finite type parameter is a Bool, indicating whether this IntegratedChain is finite or not.

source
PropCheck.IntegratedChoiceType
IntegratedChoice(is::AbstractIntegrated...)
IntegratedChoice{T} <: AbstractIntegrated{T}

An integrated shrinker for generating a value from one of any number of given AbstractIntegrated. The choice is taking uniformly random. No consideration for repeats is taken.

Is <: AbstractIntegrated{T}, but can behave (except for dispatch) like a FiniteIntegrated, if all given AbstractIntegrated are FiniteIntegrated.

source
PropCheck.IntegratedConstType
IntegratedConst{T,R,G} <: ExtentIntegrated{T}

An integrated shrinker describing a constant. The shrinker will always produce that value, which doesn't shrink.

source
PropCheck.IntegratedFiniteIteratorType
IntegratedFiniteIterator(itr[, shrink=shrink])
IntegratedFiniteIterator{T} <: FiniteIntegrated{T}

An integrated shrinker taking arbitrary iterables that have a length or a shape. Once the iterator is exhausted, the integrated shrinker produces nothing.

The values produced by this integrated shrinker shrink according to the given shrinking function.

source
PropCheck.IntegratedLengthBoundedType
IntegratedLengthBounded(is::AI, bound::Integer) where {T, AI <: AbstractIntegrated{T}}
IntegratedLengthBounded{T, AbstractIntegrated{T}} <: FiniteIntegrated{T}

An integrated shrinker bounding the number of values generated by the passed integrated shrinker. This has the ability to transform any AbstractIntegrated into a FiniteIntegrated.

The given bound must be a positive value. If a fi::FiniteIntegrated is given as the integrated shrinker, the bound is chosen to be min(length(fi), bound).

The values produced by this integrated shrinker shrink according to the shrinking function given to the original integrated shrinker wrapped by IntegratedLengthBounded.

source
PropCheck.IntegratedOnceType
IntegratedOnce(el[, shrink=shrink])
IntegratedOnce{T} <: FiniteIntegrated{T}

An integrated shrinker that produces a shrink tree with the value el at its root exactly once. Afterwards, the integrated shrinker produces nothing.

source
PropCheck.IntegratedRangeType
IntegratedRange{T,R,G,F} <: ExtentIntegrated{T}

An integrated shrinker describing a range of values.

The values created by this shrinker shrink according to the given shrinking function. The shrinking function must ensure that the produced values are always contained within the bounds of the given range.

source
PropCheck.IntegratedUniqueType
IntegratedUnique(vec::Vector{ElT}[, shrink=shrink::S]) where {ElT,S}
IntegratedUnique{T,ElT,S} <: InfiniteIntegrated{T}

An integrated shrinker, taking a vector vec. The shrinker will produce all unique values of vec in a random order before producing a value it returned before. The values produced by this shrinker shrink according to shrink.

source
PropCheck.IntegratedValType
IntegratedVal(val::V, shrink::S) where {V,S}
IntegratedVal{T,V,S} <: InfiniteIntegrated{T}

An integrated shrinker, taking a value val. The shrinker will always produce val, which shrinks according to shrink.

If V <: Number, shrinking functions given to this must produce values in

  • [typemin(V), v] if v > zero(V)
  • [v, typemax(V)] if v < zero(V)
  • no values if iszero(v)

This shrinker supports extent out of the box if V <: Number. For other types, you need to define extent(::IntegratedVal{Tree{T}})

source
PropCheck.TreeType
Tree{T}

A tree of T objects. The tree is inherently lazy; subtrees of subtrees are only generated on demand.

The subtrees field is intentionally untyped, to allow for various kinds of lazy subtree representations.

source
PropCheck.UniqueIteratorType
UniqueIterator(itr, by=identity)

A lazy iterator over unique elements that have not been produced before.

Floating Point

This iterator treats distinct bitpatterns of NaN as distinct values, unlike Base.hash.

source