From e4af8559784e851047702045ff677c9a91897fdd Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Wed, 9 Oct 2024 09:38:52 +0200 Subject: [wip] client generates applications with more than 2 terms --- rust/src/lambda.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'rust/src/lambda.rs') diff --git a/rust/src/lambda.rs b/rust/src/lambda.rs index e6102d8..ee5cb1f 100644 --- a/rust/src/lambda.rs +++ b/rust/src/lambda.rs @@ -115,6 +115,8 @@ pub fn generate_expr(size: u32, runner: &mut TestRunner) -> Value { 4 => simple_app().new_tree(runner).unwrap().current(), 5 => nested_simple_app().new_tree(runner).unwrap().current(), 6 => simple_lambda().new_tree(runner).unwrap().current(), + 7 => app_to_lambda().new_tree(runner).unwrap().current(), + 8 => multi_app().new_tree(runner).unwrap().current(), _ => todo!(), } } @@ -124,6 +126,11 @@ fn simple_app() -> impl Strategy { (leaf.clone(), leaf.clone()).prop_map(|(l, r)| Value::App(Box::new(l), Box::new(r))) } +fn multi_app() -> impl Strategy { + 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 { any::().prop_map(Value::Num) } @@ -140,9 +147,16 @@ fn any_sym() -> impl Strategy { } fn simple_lambda() -> impl Strategy { + // TODO: there's nothing to guarantee the variable appears in the body (ascii_identifier(), nested_simple_app()).prop_map(|(v, b)| Value::Lam(v, Box::new(b))) } +fn app_to_lambda() -> impl Strategy { + let lam = simple_lambda(); + let arg = prop_oneof![any_num(), any_sym(), nested_simple_app()]; + (lam, arg).prop_map(|(l, a)| Value::App(Box::new(l), Box::new(a))) +} + #[cfg(test)] mod lambda_test { use crate::parser::parse; -- cgit v1.2.3