diff --git a/fixed-hash/Cargo.toml b/fixed-hash/Cargo.toml index 27ad7d217..d66dad70e 100644 --- a/fixed-hash/Cargo.toml +++ b/fixed-hash/Cargo.toml @@ -16,7 +16,7 @@ features = ["quickcheck", "api-dummy"] [dependencies] byteorder = { version = "1.4.2", optional = true, default-features = false } -quickcheck = { version = "0.9.0", optional = true } +quickcheck = { version = "1", optional = true } rand = { version = "0.8.0", optional = true, default-features = false } rustc-hex = { version = "2.0.1", optional = true, default-features = false } static_assertions = "1.0.0" diff --git a/fixed-hash/src/hash.rs b/fixed-hash/src/hash.rs index 232245868..9dc356cdc 100644 --- a/fixed-hash/src/hash.rs +++ b/fixed-hash/src/hash.rs @@ -629,9 +629,8 @@ macro_rules! impl_quickcheck_for_fixed_hash { macro_rules! impl_quickcheck_for_fixed_hash { ( $name:ident ) => { impl $crate::quickcheck::Arbitrary for $name { - fn arbitrary(g: &mut G) -> Self { - let mut res = [0u8; $crate::core_::mem::size_of::()]; - g.fill_bytes(&mut res[..Self::len_bytes()]); + fn arbitrary(g: &mut $crate::quickcheck::Gen) -> Self { + let res: [u8; Self::len_bytes()] = $crate::core_::array::from_fn(|_| u8::arbitrary(g)); Self::from(res) } } diff --git a/uint/Cargo.toml b/uint/Cargo.toml index 1de346d84..7be3e29b1 100644 --- a/uint/Cargo.toml +++ b/uint/Cargo.toml @@ -13,8 +13,7 @@ rust-version = "1.56.1" [dependencies] byteorder = { version = "1.4.2", default-features = false } crunchy = { version = "0.2.2", default-features = false } -qc = { package = "quickcheck", version = "0.9.0", optional = true } -rand07 = { package = "rand", version = "0.7", default-features = false, optional = true } +quickcheck = { version = "1", optional = true } hex = { version = "0.4", default-features = false } static_assertions = "1.0.0" arbitrary = { version = "1.0", optional = true } @@ -22,7 +21,6 @@ arbitrary = { version = "1.0", optional = true } [features] default = ["std"] std = ["byteorder/std", "crunchy/std", "hex/std"] -quickcheck = ["qc", "rand07"] [[example]] name = "modular" diff --git a/uint/src/lib.rs b/uint/src/lib.rs index 83ab957a2..e259c79d7 100644 --- a/uint/src/lib.rs +++ b/uint/src/lib.rs @@ -23,11 +23,7 @@ pub use hex; #[cfg(feature = "quickcheck")] #[doc(hidden)] -pub use qc; - -#[cfg(feature = "quickcheck")] -#[doc(hidden)] -pub use rand07; +pub use quickcheck; #[cfg(feature = "arbitrary")] #[doc(hidden)] diff --git a/uint/src/uint.rs b/uint/src/uint.rs index 1b633fc79..728957dcc 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -1741,28 +1741,33 @@ macro_rules! construct_uint { #[doc(hidden)] macro_rules! impl_quickcheck_arbitrary_for_uint { ($uint: ty, $n_bytes: tt) => { - impl $crate::qc::Arbitrary for $uint { - fn arbitrary(g: &mut G) -> Self { - let mut res = [0u8; $n_bytes]; - - use $crate::rand07::Rng; - let p: f64 = $crate::rand07::rngs::OsRng.gen(); + impl $crate::quickcheck::Arbitrary for $uint { + fn arbitrary(g: &mut $crate::quickcheck::Gen) -> Self { + let p = usize::arbitrary(g) % 100; // make it more likely to generate smaller numbers that // don't use up the full $n_bytes let range = // 10% chance to generate number that uses up to $n_bytes - if p < 0.1 { + if p < 10 { $n_bytes // 10% chance to generate number that uses up to $n_bytes / 2 - } else if p < 0.2 { + } else if p < 20 { $n_bytes / 2 // 80% chance to generate number that uses up to $n_bytes / 5 } else { $n_bytes / 5 }; - let size = g.gen_range(0, range); - g.fill_bytes(&mut res[..size]); + let range = $crate::core_::cmp::max(range, 1); + let size: usize = usize::arbitrary(g) % range; + + let res: [u8; $n_bytes] = $crate::core_::array::from_fn(|i| { + if i > size { + 0 + } else { + u8::arbitrary(g) + } + }); res.as_ref().into() } diff --git a/uint/tests/uint_tests.rs b/uint/tests/uint_tests.rs index f378423f1..9ef7f2e19 100644 --- a/uint/tests/uint_tests.rs +++ b/uint/tests/uint_tests.rs @@ -1157,7 +1157,7 @@ pub mod laws { macro_rules! uint_laws { ($mod_name:ident, $uint_ty:ident) => { mod $mod_name { - use qc::{TestResult, quickcheck}; + use quickcheck::{TestResult, quickcheck}; use super::$uint_ty; quickcheck! {