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
Vs 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
StrategyforStringso that a sensibleDefaultcan be given. The default is a string of non-control characters.
Traits§
Functions§
- any
- Generates a
StrategyproducingArbitraryvalues ofA. Unlikearbitrary, it should be used for being explicit on whatAis. For clarity, this may be a good idea. - any_
with - Generates a
StrategyproducingArbitraryvalues ofAwith the given configuration arguments passed inargs. Unlikearbitrary_with, it should be used for being explicit on whatAis. For clarity, this may be a good idea. - arbitrary
- Generates a
StrategyproducingArbitraryvalues ofA. Works better with type inference thanany::<A>(). - arbitrary_
with - Generates a
StrategyproducingArbitraryvalues ofAwith the given configuration arguments passed inargs. Works better with type inference thanany_with::<A>(args). - prob
- Creates a
Probabilityfrom some value that is convertible into it. - size_
bounds - Creates a
SizeBoundsfrom some value that is convertible into it.
Type Aliases§
- FnGenerator
- Shorthand for
Generator<V, fn() -> V>. - Mapped
- A normal map from a strategy of
ItoO. - MappedF
- A map from a strategy of
ItoOusing theFromtrait for conversion. - MappedS
- A static map from a strategy of
ItoO. - Params
For ParamsForallows you to mention the type ofParametersfor the input typeAwithout directly using associated types or without resorting to existential types. This way, if implementation ofArbitrarychanges, your tests should not break. Additionally, if you have a customArbitrary::Parameterstype, or use aArbitrary::Parameterstype with generics in it where you’ve provided a custom type for the type parameter, you need not export your type ifAisArbitraryas theParameterstype is still reachable fromParamsFor.- Params
Type ParamsTypeallows you to mention the type ofParametersfor the input typeAwithout directly using associated types or without resorting to existential types. This way, if implementation ofArbitrarychanges, your tests should not break. Additionally, if you have a customArbitrary::Parameterstype, or use aArbitrary::Parameterstype with generics in it where you’ve provided a custom type for the type parameter, you need not export your type ifAisArbitraryas theParameterstype is still reachable fromParamsType.- Strategy
For StrategyForallows you to mention the type ofStrategyfor the input typeAwithout directly using associated types or without resorting to existential types. This way, if implementation ofArbitrarychanges, your tests should not break. This can be especially beneficial when the type ofStrategythat you are dealing with is very long in name (the case with generics). Additionally, if you have a customStrategytype, or use aStrategytype with generics in it where you’ve provided a custom type for the type parameter, you need not export your type ifAisArbitraryas theStrategytype is still reachable fromStrategyFor.- Strategy
Type StrategyTypeallows you to mention the type ofStrategyfor the input typeAwithout directly using associated types or without resorting to existential types. This way, if implementation ofArbitrarychanges, your tests should not break. This can be especially beneficial when the type ofStrategythat you are dealing with is very long in name (the case with generics). Additionally, if you have a customStrategytype, or use aStrategytype with generics in it where you’ve provided a custom type for the type parameter, you need not export your type ifAisArbitraryas theStrategytype is still reachable fromStrategyType.