From 623150814fb5289b9b7d09bb4a490d5860ca01a5 Mon Sep 17 00:00:00 2001 From: nicoo Date: Mon, 17 May 2021 19:59:27 +0200 Subject: [PATCH] Implement Arbitrary for fixed-sized arrays of Arbitrary elements --- Cargo.toml | 3 ++- src/arbitrary.rs | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 17cc17a..eebb231 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "quickcheck" -version = "1.0.3" #:version +version = "1.0.3" #:version authors = ["Andrew Gallant "] description = "Automatic property based testing with shrinking." documentation = "https://docs.rs/quickcheck" @@ -28,3 +28,4 @@ name = "quickcheck" env_logger = { version = "0.8.2", default-features = false, optional = true } log = { version = "0.4", optional = true } rand = { version = "0.8", default-features = false, features = ["getrandom", "small_rng"] } +array-init = "2" diff --git a/src/arbitrary.rs b/src/arbitrary.rs index 92f893b..1b94bf2 100644 --- a/src/arbitrary.rs +++ b/src/arbitrary.rs @@ -195,6 +195,12 @@ impl Arbitrary for Result { } } +impl Arbitrary for [T; N] { + fn arbitrary(g: &mut Gen) -> Self { + array_init::array_init(|_| T::arbitrary(g)) + } +} + macro_rules! impl_arb_for_single_tuple { ($(($type_param:ident, $tuple_index:tt),)*) => { impl<$($type_param),*> Arbitrary for ($($type_param,)*)