diff options
| author | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-10-08 22:32:44 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-10-08 22:32:44 +0200 |
| commit | e8ab131a2b54aa4252ccda3261a0a6a2ade6a273 (patch) | |
| tree | e3910c5da9fb91b707f4860ed829918c0d062b0f /rust/src | |
| parent | 5d24ab1e8765dbd5001aba21fe59d754224720f5 (diff) | |
| download | lambda-nantes-e8ab131a2b54aa4252ccda3261a0a6a2ade6a273.tar.gz | |
Generate nested binary applications
Also factor out common strategies into functions
Diffstat (limited to 'rust/src')
| -rw-r--r-- | rust/src/lambda.rs | 22 | ||||
| -rw-r--r-- | rust/src/web.rs | 16 |
2 files changed, 34 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; diff --git a/rust/src/web.rs b/rust/src/web.rs index af27eda..3d9fcda 100644 --- a/rust/src/web.rs +++ b/rust/src/web.rs @@ -432,6 +432,22 @@ mod app_tests { } #[test] + async fn client_generates_nested_applications_and_constants_at_level_5() { + let mut client = client(); + client.grade = 5; + + let (input, _) = client.generate_expr(); + + let parsed = parse(&input); + match &parsed[..] { + [Value::App(_, _)] => (), + [Value::Sym(_)] => (), + [Value::Num(_)] => (), + _ => panic!("Expected symbol, got {:?}", parsed), + } + } + + #[test] async fn client_increases_grade_on_successful_test() { let mut client = client(); let expected = "1".to_string(); |
