Module time::quickcheck

source ·
Available on crate feature quickcheck only.
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()
        }
    }
}
Run

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§

  • Obtain an arbitrary value between the minimum and maximum inclusive.