diff options
Diffstat (limited to 'rust/src/lambda.rs')
| -rw-r--r-- | rust/src/lambda.rs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/rust/src/lambda.rs b/rust/src/lambda.rs index e22d210..406aebf 100644 --- a/rust/src/lambda.rs +++ b/rust/src/lambda.rs @@ -111,19 +111,33 @@ pub fn generate_expr(size: u32, runner: &mut TestRunner) -> Value { Value::Num(n.into()) } 2 => Value::Sym(ascii_identifier().new_tree(runner).unwrap().current()), - 3 => Value::Sym(identifier().new_tree(runner).unwrap().current()), + 3 => any_sym().new_tree(runner).unwrap().current(), 4 => simple_app().new_tree(runner).unwrap().current(), + 5 => nested_simple_app().new_tree(runner).unwrap().current(), _ => todo!(), } } fn simple_app() -> impl Strategy<Value = Value> { - let any_num = any::<i32>().prop_map(Value::Num); - let any_sym = identifier().prop_map(Value::Sym); - let leaf = prop_oneof![any_num, any_sym]; + let leaf = prop_oneof![any_num(), any_sym()]; (leaf.clone(), leaf.clone()).prop_map(|(l, r)| Value::App(Box::new(l), Box::new(r))) } +fn any_num() -> impl Strategy<Value = Value> { + any::<i32>().prop_map(Value::Num) +} + +fn nested_simple_app() -> impl Strategy<Value = Value> { + let leaf = prop_oneof![any_num(), any_sym()]; + leaf.prop_recursive(4, 128, 5, move |inner| { + (inner.clone(), inner.clone()).prop_map(|(l, r)| Value::App(Box::new(l), Box::new(r))) + }) +} + +fn any_sym() -> impl Strategy<Value = Value> { + identifier().prop_map(Value::Sym) +} + #[cfg(test)] mod lambda_test { use crate::parser::parse; |
