1use {core::convert::Infallible, pbt::Pbt};
2
3#[non_exhaustive]
4#[derive(Clone, Debug, Eq, PartialEq, Pbt)]
5pub enum Foo {
6 Bar,
7 Baz { a: u64, b: u64, c: Vec<Foo> },
8}
9
10#[derive(Clone, Debug, Eq, PartialEq, Pbt)]
11pub enum PartiallyInstantiable {
12 Instantiable,
13 Uninstantiable(Infallible),
14}
15
16impl Foo {
17 #[inline]
18 #[must_use]
19 pub fn bus_factor(&self) -> usize {
20 match *self {
21 Self::Bar => 0,
22 Self::Baz { ref c, .. } => c.len(),
23 }
24 }
25}
26
27#[cfg(test)]
28mod test {
29 use {super::*, pbt::search, pretty_assertions::assert_eq};
30
31 #[test]
32 fn instantiability_logic() {
33 search::assert_eq(1_000, |pi: &PartiallyInstantiable| {
34 (pi.clone(), PartiallyInstantiable::Instantiable)
35 });
36 }
37
38 #[test]
39 fn search_and_minimize() {
40 let maybe_witness: Option<Foo> = search::witness(1_000, |foo: &Foo| foo.bus_factor() >= 3);
41 assert_eq!(
42 maybe_witness,
43 Some(Foo::Baz {
44 a: 0,
45 b: 0,
46 c: vec![Foo::Bar, Foo::Bar, Foo::Bar],
47 }),
48 );
49 }
50}