1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use crate::{Slice, Vec};
use quickcheck1::Arbitrary;

impl<T> Arbitrary for Vec<T>
where
    T: Arbitrary,
{
    fn arbitrary(g: &mut quickcheck1::Gen) -> Self {
        let mut it = Vec::of(T::arbitrary(g));
        it.extend(alloc::vec::Vec::arbitrary(g));
        it
    }
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
        let raw = self.clone().into_vec();
        Box::new(Arbitrary::shrink(&raw).flat_map(Vec::new))
    }
}

impl<T> Arbitrary for Box<Slice<T>>
where
    T: Arbitrary,
{
    fn arbitrary(g: &mut quickcheck1::Gen) -> Self {
        let mut it = Vec::of(T::arbitrary(g));
        it.extend(alloc::vec::Vec::arbitrary(g));
        it.into_boxed_slice()
    }
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
        let raw = Vec::from(self.clone());
        Box::new(Arbitrary::shrink(&raw).map(Self::from))
    }
}