proptest/arbitrary/
arrays.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 arrays.
11
12use crate::arbitrary::{any_with, Arbitrary};
13use crate::array::UniformArrayStrategy;
14
15macro_rules! array {
16    ($($n: expr),*) => { $(
17        impl<A: Arbitrary> Arbitrary for [A; $n] {
18            type Parameters = A::Parameters;
19            type Strategy = UniformArrayStrategy<A::Strategy, [A; $n]>;
20            fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
21                let base = any_with::<A>(args);
22                UniformArrayStrategy::new(base)
23            }
24        }
25    )* };
26}
27
28array!(
29    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
30    22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
31);
32
33#[cfg(test)]
34mod test {
35    no_panic_test!(
36        array_16 => [u8; 16]
37    );
38}