Expand description
Implementations of the quickcheck::Arbitrary
trait.
This enables users to write tests such as this, and have test values provided automatically:
โ
use quickcheck::quickcheck;
use time::Date;
struct DateRange {
from: Date,
to: Date,
}
impl DateRange {
fn new(from: Date, to: Date) -> Result<Self, ()> {
Ok(DateRange { from, to })
}
}
quickcheck! {
fn date_range_is_well_defined(from: Date, to: Date) -> bool {
let r = DateRange::new(from, to);
if from <= to {
r.is_ok()
} else {
r.is_err()
}
}
}
An implementation for Instant
is intentionally omitted since its values are only meaningful in
relation to a Duration
, and obtaining an Instant
from a Duration
is very simple
anyway.
Macrosยง
- arbitrary_
between ๐Obtain an arbitrary value between the minimum and maximum inclusive.