//! Implementations of the [`quickcheck::Arbitrary`](quickcheck::Arbitrary) trait. //! //! This enables users to write tests such as this, and have test values provided automatically: //! //! ```ignore //! # #![allow(dead_code)] //! 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.
use alloc::boxed::Box;
use quickcheck::{empty_shrinker, single_shrinker, Arbitrary, Gen};
usecrate::{Date, Duration, Month, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset, Weekday};
/// Obtain an arbitrary value between the minimum and maximum inclusive.
macro_rules! arbitrary_between {
($type:ty; $gen:expr, $min:expr, $max:expr) => {{ let min = $min; let max = $max; let range = max - min;
<$type>::arbitrary($gen).rem_euclid(range + 1) + min
}};
}
impl Arbitrary for Date { fn arbitrary(g: &mutGen) -> Self { Self::from_julian_day_unchecked(arbitrary_between!(
i32;
g, Self::MIN.to_julian_day(), Self::MAX.to_julian_day()
))
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.