Crate proptest_arbitrary [] [src]

NOTE: This version is still WIP; don't use yet, just reserving at crates.io.

Proptest is a property testing framework (i.e., the QuickCheck family) inspired by the Hypothesis framework for Python.

This crate, proptest-arbitrary, additionally provides an Arbitrary trait which allows you to have a canonical Strategy per type. This is the equivalent of Haskell QuickCheck's implementation of Arbitrary. In this interpretation of Arbitrary, Strategy is the equivalent of the Gen monad.

Arbitrary is currently implemented as:

Be careful when using this code, it's not being tested!
/// Arbitrary determines a canonical Strategy [..]
pub trait Arbitrary<'a> : Sized + Debug {
   fn arbitrary() -> Self::Strategy {
       Self::arbitrary_with(Default::default())
   }

   fn arbitrary_with(args: Self::Parameters) -> Self::Strategy;

   type Parameters: Default;

    type Strategy: Strategy<Value = Self::ValueTree>;

    /// NOTE:
    /// This type should NOT be relied upon outside of this crate
    /// other than for implementing `Arbitrary` for other types.
    type ValueTree: ValueTree<Value = Self>;

}

Structs

CharParam

Parameters to pass to proptest::char::CharStrategy::new(..).

Generator

Strategy for generating Vs from an Fn() -> V. It's not a very interesting Strategy, but required sometimes when the only means of creating an object of some type is via a function while type type is also not Clone.

Probability

A probability in the range [0.0, 1.0] with a default of 0.5.

SizeBounds

The minimum and maximum bounds on the size of a collection. The interval must form a subset of [0, std::usize::MAX).

StringParam

Wraps the regex that forms the Strategy for String so that a sensible Default can be given. The default is a string of non-control characters.

Traits

Arbitrary

Arbitrary determines a canonical Strategy for the implementing type.

Functions

any

Generates a Strategy producing Arbitrary values of A. Unlike arbitrary, it should be used for being explicit on what A is. For clarity, this may be a good idea.

any_with

Generates a Strategy producing Arbitrary values of A with the given configuration arguments passed in args. Unlike arbitrary_with, it should be used for being explicit on what A is. For clarity, this may be a good idea.

arbitrary

Generates a Strategy producing Arbitrary values of A. Works better with type inference than any::<A>().

arbitrary_with

Generates a Strategy producing Arbitrary values of A with the given configuration arguments passed in args. Works better with type inference than any_with::<A>(args).

prob

Creates a Probability from some value that is convertible into it.

size_bounds

Creates a SizeBounds from some value that is convertible into it.

Type Definitions

FnGenerator

Shorthand for Generator<V, fn() -> V>.

Mapped

A normal map from a strategy of I to O.

MappedF

A map from a strategy of I to O using the From trait for conversion.

MappedS

A static map from a strategy of I to O.

ParamsFor

ParamsFor allows you to mention the type of Parameters for the input type A without directly using associated types or without resorting to existential types. This way, if implementation of Arbitrary changes, your tests should not break. Additionally, if you have a custom Arbitrary::Parameters type, or use a Arbitrary::Parameters type with generics in it where you've provided a custom type for the type parameter, you need not export your type if A is Arbitrary as the Parameters type is still reachable from ParamsFor.

ParamsType

ParamsType allows you to mention the type of Parameters for the input type A without directly using associated types or without resorting to existential types. This way, if implementation of Arbitrary changes, your tests should not break. Additionally, if you have a custom Arbitrary::Parameters type, or use a Arbitrary::Parameters type with generics in it where you've provided a custom type for the type parameter, you need not export your type if A is Arbitrary as the Parameters type is still reachable from ParamsType.

StrategyFor

StrategyFor allows you to mention the type of Strategy for the input type A without directly using associated types or without resorting to existential types. This way, if implementation of Arbitrary changes, your tests should not break. This can be especially beneficial when the type of Strategy that you are dealing with is very long in name (the case with generics). Additionally, if you have a custom Strategy type, or use a Strategy type with generics in it where you've provided a custom type for the type parameter, you need not export your type if A is Arbitrary as the Strategy type is still reachable from StrategyFor.

StrategyType

StrategyType allows you to mention the type of Strategy for the input type A without directly using associated types or without resorting to existential types. This way, if implementation of Arbitrary changes, your tests should not break. This can be especially beneficial when the type of Strategy that you are dealing with is very long in name (the case with generics). Additionally, if you have a custom Strategy type, or use a Strategy type with generics in it where you've provided a custom type for the type parameter, you need not export your type if A is Arbitrary as the Strategy type is still reachable from StrategyType.