# [−][src]Crate proptest_recurse

This crate provides a helper struct for defining mutually recursive strategies with `proptest`. The `prop_recursive` combinator is useful for defining simple recursive strategies but for two or more mutually recursive strategies it becomes cumbersome to use. `StrategySet` aims to solve this problem.

# Examples

Suppose we have the following mutually recursive types `First` and `Second`

```#[derive(Clone, Debug)]
enum First {
Zero,
Second(Vec<Second>),
}

#[derive(Clone, Debug)]
enum Second {
Zero,
First(First),
}```

We can define strategies for each using a `StrategySet`

```use proptest_recurse::{StrategySet, StrategyExt};

fn arb_first(set: &mut StrategySet) -> SBoxedStrategy<First> {
Just(First::Zero).prop_mutually_recursive(5, 32, 8, set, |set| {
vec(set.get::<Second, _>(arb_second), 0..8)
.prop_map(First::Second)
.sboxed()
})
}

fn arb_second(set: &mut StrategySet) -> SBoxedStrategy<Second> {
Just(Second::Zero)
.prop_mutually_recursive(3, 32, 1, set, |set| {
set.get::<First, _>(arb_first)
.prop_map(Second::First)
.sboxed()
}).sboxed()
}```

To use these strategies, simply pass in an empty `StrategySet`

```proptest! {
#[test]
fn create(_ in arb_first(&mut Default::default())) {}
}```

## Structs

 StrategySet A collection of strategies that depend on each other. This type is cheap to clone.

## Traits

 StrategyExt Extension methods for strategies.