Expand description
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:
ⓘ
/// 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§
- Char
Param - Parameters to pass to
proptest::char::CharStrategy::new(..)
. - Generator
- Strategy for generating
V
s from anFn() -> 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 of0.5
. - Size
Bounds - The minimum and maximum bounds on the size of a collection.
The interval must form a subset of
[0, std::usize::MAX)
. - String
Param - Wraps the regex that forms the
Strategy
forString
so that a sensibleDefault
can be given. The default is a string of non-control characters.
Traits§
Functions§
- any
- Generates a
Strategy
producingArbitrary
values ofA
. Unlikearbitrary
, it should be used for being explicit on whatA
is. For clarity, this may be a good idea. - any_
with - Generates a
Strategy
producingArbitrary
values ofA
with the given configuration arguments passed inargs
. Unlikearbitrary_with
, it should be used for being explicit on whatA
is. For clarity, this may be a good idea. - arbitrary
- Generates a
Strategy
producingArbitrary
values ofA
. Works better with type inference thanany::<A>()
. - arbitrary_
with - Generates a
Strategy
producingArbitrary
values ofA
with the given configuration arguments passed inargs
. Works better with type inference thanany_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 Aliases§
- FnGenerator
- Shorthand for
Generator<V, fn() -> V>
. - Mapped
- A normal map from a strategy of
I
toO
. - MappedF
- A map from a strategy of
I
toO
using theFrom
trait for conversion. - MappedS
- A static map from a strategy of
I
toO
. - Params
For ParamsFor
allows you to mention the type ofParameters
for the input typeA
without directly using associated types or without resorting to existential types. This way, if implementation ofArbitrary
changes, your tests should not break. Additionally, if you have a customArbitrary::Parameters
type, or use aArbitrary::Parameters
type with generics in it where you’ve provided a custom type for the type parameter, you need not export your type ifA
isArbitrary
as theParameters
type is still reachable fromParamsFor
.- Params
Type ParamsType
allows you to mention the type ofParameters
for the input typeA
without directly using associated types or without resorting to existential types. This way, if implementation ofArbitrary
changes, your tests should not break. Additionally, if you have a customArbitrary::Parameters
type, or use aArbitrary::Parameters
type with generics in it where you’ve provided a custom type for the type parameter, you need not export your type ifA
isArbitrary
as theParameters
type is still reachable fromParamsType
.- Strategy
For StrategyFor
allows you to mention the type ofStrategy
for the input typeA
without directly using associated types or without resorting to existential types. This way, if implementation ofArbitrary
changes, your tests should not break. This can be especially beneficial when the type ofStrategy
that you are dealing with is very long in name (the case with generics). Additionally, if you have a customStrategy
type, or use aStrategy
type with generics in it where you’ve provided a custom type for the type parameter, you need not export your type ifA
isArbitrary
as theStrategy
type is still reachable fromStrategyFor
.- Strategy
Type StrategyType
allows you to mention the type ofStrategy
for the input typeA
without directly using associated types or without resorting to existential types. This way, if implementation ofArbitrary
changes, your tests should not break. This can be especially beneficial when the type ofStrategy
that you are dealing with is very long in name (the case with generics). Additionally, if you have a customStrategy
type, or use aStrategy
type with generics in it where you’ve provided a custom type for the type parameter, you need not export your type ifA
isArbitrary
as theStrategy
type is still reachable fromStrategyType
.