1 use super::{BigInt, Sign}; 2 3 #[cfg(feature = "quickcheck")] 4 use crate::std_alloc::Box; 5 use crate::BigUint; 6 7 #[cfg(feature = "quickcheck")] 8 impl quickcheck::Arbitrary for BigInt { arbitrary(g: &mut quickcheck::Gen) -> Self9 fn arbitrary(g: &mut quickcheck::Gen) -> Self { 10 let positive = bool::arbitrary(g); 11 let sign = if positive { Sign::Plus } else { Sign::Minus }; 12 Self::from_biguint(sign, BigUint::arbitrary(g)) 13 } 14 shrink(&self) -> Box<dyn Iterator<Item = Self>>15 fn shrink(&self) -> Box<dyn Iterator<Item = Self>> { 16 let sign = self.sign(); 17 let unsigned_shrink = self.data.shrink(); 18 Box::new(unsigned_shrink.map(move |x| BigInt::from_biguint(sign, x))) 19 } 20 } 21 22 #[cfg(feature = "arbitrary")] 23 impl arbitrary::Arbitrary<'_> for BigInt { arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self>24 fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> { 25 let positive = bool::arbitrary(u)?; 26 let sign = if positive { Sign::Plus } else { Sign::Minus }; 27 Ok(Self::from_biguint(sign, BigUint::arbitrary(u)?)) 28 } 29 arbitrary_take_rest(mut u: arbitrary::Unstructured<'_>) -> arbitrary::Result<Self>30 fn arbitrary_take_rest(mut u: arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> { 31 let positive = bool::arbitrary(&mut u)?; 32 let sign = if positive { Sign::Plus } else { Sign::Minus }; 33 Ok(Self::from_biguint(sign, BigUint::arbitrary_take_rest(u)?)) 34 } 35 size_hint(depth: usize) -> (usize, Option<usize>)36 fn size_hint(depth: usize) -> (usize, Option<usize>) { 37 arbitrary::size_hint::and(bool::size_hint(depth), BigUint::size_hint(depth)) 38 } 39 } 40