proptest/arbitrary/
primitives.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 primitive types.
11
12use crate::bool;
13use crate::char;
14use crate::num::{
15    f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize,
16};
17
18arbitrary!(bool, i8, i16, i32, i64, isize, u8, u16, u32, u64, usize, i128, u128);
19
20// Note that for floating point types we limit the space since a lot of code
21// isn't prepared for (and is not intended to be) things like NaN and infinity.
22arbitrary!(f32, f32::Any; {
23    f32::POSITIVE | f32::NEGATIVE | f32::ZERO | f32::SUBNORMAL | f32::NORMAL
24});
25arbitrary!(f64, f64::Any; {
26    f64::POSITIVE | f64::NEGATIVE | f64::ZERO | f64::SUBNORMAL | f64::NORMAL
27});
28
29arbitrary!(char, char::CharStrategy<'static>; char::any());
30
31#[cfg(test)]
32mod test {
33    no_panic_test!(
34        bool => bool,
35        char => char,
36        f32 => f32, f64 => f64,
37        isize => isize, usize => usize,
38        i8 => i8, i16 => i16, i32 => i32, i64 => i64, i128 => i128,
39        u8 => u8, u16 => u16, u32 => u32, u64 => u64, u128 => u128
40    );
41}