diff options
| author | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-10-09 09:38:52 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-10-09 09:38:52 +0200 |
| commit | e4af8559784e851047702045ff677c9a91897fdd (patch) | |
| tree | 36cb8b81a521f653ed17703639682de24ce6405f /rust/src/lambda.rs | |
| parent | 67502b58c733b755f658f526aff0536828cd7757 (diff) | |
| download | lambda-nantes-e4af8559784e851047702045ff677c9a91897fdd.tar.gz | |
[wip] client generates applications with more than 2 terms
Diffstat (limited to 'rust/src/lambda.rs')
| -rw-r--r-- | rust/src/lambda.rs | 14 |
1 files changed, 14 insertions, 0 deletions
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<Value = Value> { (leaf.clone(), leaf.clone()).prop_map(|(l, r)| Value::App(Box::new(l), Box::new(r))) } +fn multi_app() -> impl Strategy<Value = Value> { + 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) } @@ -140,9 +147,16 @@ fn any_sym() -> impl Strategy<Value = Value> { } fn simple_lambda() -> impl Strategy<Value = Value> { + // 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<Value = Value> { + 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; |
