• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![cfg(any(feature = "quickcheck", feature = "arbitrary"))]
2 
3 use super::{biguint_from_vec, BigUint};
4 
5 use crate::big_digit::BigDigit;
6 #[cfg(feature = "quickcheck")]
7 use alloc::boxed::Box;
8 use alloc::vec::Vec;
9 
10 #[cfg(feature = "quickcheck")]
11 #[cfg_attr(docsrs, doc(cfg(feature = "quickcheck")))]
12 impl quickcheck::Arbitrary for BigUint {
arbitrary(g: &mut quickcheck::Gen) -> Self13     fn arbitrary(g: &mut quickcheck::Gen) -> Self {
14         // Use arbitrary from Vec
15         biguint_from_vec(Vec::<BigDigit>::arbitrary(g))
16     }
17 
shrink(&self) -> Box<dyn Iterator<Item = Self>>18     fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
19         // Use shrinker from Vec
20         Box::new(self.data.shrink().map(biguint_from_vec))
21     }
22 }
23 
24 #[cfg(feature = "arbitrary")]
25 #[cfg_attr(docsrs, doc(cfg(feature = "arbitrary")))]
26 impl arbitrary::Arbitrary<'_> for BigUint {
arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self>27     fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
28         Ok(biguint_from_vec(Vec::<BigDigit>::arbitrary(u)?))
29     }
30 
arbitrary_take_rest(u: arbitrary::Unstructured<'_>) -> arbitrary::Result<Self>31     fn arbitrary_take_rest(u: arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
32         Ok(biguint_from_vec(Vec::<BigDigit>::arbitrary_take_rest(u)?))
33     }
34 
size_hint(depth: usize) -> (usize, Option<usize>)35     fn size_hint(depth: usize) -> (usize, Option<usize>) {
36         Vec::<BigDigit>::size_hint(depth)
37     }
38 }
39