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
27arbitrary!(FpCategory,
28    TupleUnion<(WA<Just<Self>>, WA<Just<Self>>, WA<Just<Self>>,
29                WA<Just<Self>>, WA<Just<Self>>)>;
30    {
31        use core::num::FpCategory::*;
32        prop_oneof![
33            Just(Nan),
34            Just(Infinite),
35            Just(Zero),
36            Just(Subnormal),
37            Just(Normal),
38        ]
39    }
40);
41
42#[cfg(test)]
43mod test {
44    no_panic_test!(
45        parse_float_error => ParseFloatError,
46        parse_int_error => ParseIntError,
47        wrapping => Wrapping<u8>,
48        fp_category => FpCategory
49    );
50
51    #[cfg(feature = "unstable")]
52    no_panic_test!(
53        try_from_int_error => TryFromIntError
54    );
55}