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.map — Method
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.filter — Method
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.filter — Method
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.map — Method
map(f, i::AbstractIntegrated) -> AbstractIntegrated

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

source
PropCheck.array — Method
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.assemble — Method
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.check — Method
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.extent — Method
extent(::ExtentIntegrated) -> Tuple{T,T} where T

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

source
PropCheck.freeze — Method
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.iconst — Method
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.ifloat — Method
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.ifloatinfnan — Method
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.inegint — Method
inegint(::Type{T}) where T <: Union{Int8, Int16, Int32, Int64, Int128}

An integrated shrinker producing negative values of type T.

source
PropCheck.iposint — Method
iposint(::Type{T}) where T <: Union{Int8, Int16, Int32, Int64, Int128}

An integrated shrinker producing positive values of type T.

source
PropCheck.isample — Function
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.isample — Function
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.iunique — Method
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.ival — Method
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.nanHash — Function
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.shrinkTowards — Function
shrinkTowards(to::T) -> (x::T -> T[...])

Constructs a shrinker function that shrinks given values towards to.

source
PropCheck.str — Function
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.tear — Method
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.tuple — Method
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.unfold — Method
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.vector — Method
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.Flatten — Type
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.Integrated — Type
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.IntegratedChain — Type
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.IntegratedConst — Type
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.IntegratedFiniteIterator — Type
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.IntegratedLengthBounded — Type
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.IntegratedOnce — Type
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.IntegratedRange — Type
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.IntegratedUnique — Type
IntegratedUnique(vec::Vector{ElT}, 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.IntegratedVal — Type
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.Tree — Type
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.UniqueIterator — Type
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