proptest/arbitrary/_core/
num.rs

1//-
2// Copyright 2017, 2018 The proptest developers
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10//! Arbitrary implementations for `std::num`.
11
12use core::num::*;
13
14use crate::strategy::*;
15
16arbitrary!(ParseFloatError; "".parse::<f32>().unwrap_err());
17arbitrary!(ParseIntError; "".parse::<u32>().unwrap_err());
18
19#[cfg(feature = "unstable")]
20arbitrary!(TryFromIntError; {
21    use core::convert::TryFrom;
22    u8::try_from(-1).unwrap_err()
23});
24
25wrap_ctor!(Wrapping, Wrapping);
26
27wrap_ctor!(Saturating, Saturating);
28
29arbitrary!(FpCategory,
30    TupleUnion<(WA<Just<Self>>, WA<Just<Self>>, WA<Just<Self>>,
31                WA<Just<Self>>, WA<Just<Self>>)>;
32    {
33        use core::num::FpCategory::*;
34        prop_oneof![
35            Just(Nan),
36            Just(Infinite),
37            Just(Zero),
38            Just(Subnormal),
39            Just(Normal),
40        ]
41    }
42);
43
44#[cfg(test)]
45mod test {
46    no_panic_test!(
47        parse_float_error => ParseFloatError,
48        parse_int_error => ParseIntError,
49        wrapping => Wrapping<u8>,
50        saturating => Saturating<u8>,
51        fp_category => FpCategory
52    );
53
54    #[cfg(feature = "unstable")]
55    no_panic_test!(
56        try_from_int_error => TryFromIntError
57    );
58}