diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-10-09 11:57:50 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-10-09 11:57:50 +0200 |
| commit | ed4b4863df6f56949edf86115c606f021237c651 (patch) | |
| tree | 5578f89fe87e8eacc3a938125bdf49ed3076980f | |
| parent | 65afa24d40811218168531d25999572c0e17d21d (diff) | |
| download | lambda-nantes-ed4b4863df6f56949edf86115c606f021237c651.tar.gz | |
feat: work with Value at generation and convert later
| -rw-r--r-- | lambda-calcul/rust/src/web.rs | 97 |
1 files changed, 47 insertions, 50 deletions
diff --git a/lambda-calcul/rust/src/web.rs b/lambda-calcul/rust/src/web.rs index ac618b1..353b34b 100644 --- a/lambda-calcul/rust/src/web.rs +++ b/lambda-calcul/rust/src/web.rs @@ -2,6 +2,7 @@ use actix_web::{get, middleware::Logger, post, web, App, HttpResponse, HttpServe use chrono::{DateTime, Utc}; use clap::Parser; use handlebars::{DirectorySourceOptions, Handlebars}; +use lambda::ast::Value; use log::info; use proptest::test_runner::{Config, RngAlgorithm, TestRng, TestRunner}; use rand::Rng; @@ -115,32 +116,20 @@ impl Client { self.delay } - fn generate_expr(&mut self) -> (String, String) { + fn generate_expr(&mut self) -> (Vec<Value>, Vec<Value>) { if self.grade >= 10 { self.generate_exprs() } else { let input = generate_expr(self.grade.into(), &mut self.runner); let expected = eval_whnf(&input, &mut Environment::new()); - (input.to_string(), expected.to_string()) + (vec![input], vec![expected]) } } - fn generate_exprs(&mut self) -> (String, String) { - let exprs = generate_exprs(self.grade.into(), &mut self.runner); - let input = exprs - .iter() - .map(|v| format!("{}", v)) - .collect::<Vec<_>>() - .join("\n"); - let expected = eval_all(&exprs); - ( - input, - expected - .iter() - .map(|v| format!("{}", v)) - .collect::<Vec<_>>() - .join("\n"), - ) + fn generate_exprs(&mut self) -> (Vec<Value>, Vec<Value>) { + let input = generate_exprs(self.grade.into(), &mut self.runner); + let expected = eval_all(&input); + (input, expected) } /// Applies a `Test` to update client's state @@ -356,7 +345,7 @@ async fn main() -> std::io::Result<()> { .await } -fn get_test(client_m: &Mutex<Client>) -> (String, String, String) { +fn get_test(client_m: &Mutex<Client>) -> (Vec<Value>, String, Vec<Value>) { let mut client = client_m.lock().unwrap(); let (input, expected) = client.generate_expr(); (input, client.url.clone(), expected) @@ -369,9 +358,26 @@ async fn send_tests(client_m: Arc<Mutex<Client>>) { { let (input, url, expected) = get_test(&client_m); - let response = send_test(&input, &url, sleep).await; - - apply_result(&client_m, expected, response); + let response = send_test( + &input + .iter() + .map(|v| format!("{}", v)) + .collect::<Vec<_>>() + .join("\n"), + &url, + sleep, + ) + .await; + + apply_result( + &client_m, + expected + .iter() + .map(|v| format!("{}", v)) + .collect::<Vec<_>>() + .join("\n"), + response, + ); } } } @@ -629,7 +635,7 @@ mod app_tests { let (input, _) = client.generate_expr(); - match parse(&input)[..] { + match &input[..] { [Value::Num(_)] => (), _ => panic!("Expected constant 3"), } @@ -652,12 +658,11 @@ mod app_tests { let (input, _) = client.generate_expr(); - let parsed = parse(&input); - match &parsed[..] { + match &input[..] { [Value::Sym(name)] => { assert!(name.chars().all(|c| c.is_ascii_alphanumeric())); } - _ => panic!("Expected symbol, got {:?}", parsed), + _ => panic!("Expected symbol, got {:?}", input), } } @@ -668,10 +673,9 @@ mod app_tests { let (input, _) = client.generate_expr(); - let parsed = parse(&input); - match &parsed[..] { + match &input[..] { [Value::Sym(_)] => (), - _ => panic!("Expected symbol, got {:?}", parsed), + _ => panic!("Expected symbol, got {:?}", input), } } @@ -682,10 +686,9 @@ mod app_tests { let (input, _) = client.generate_expr(); - let parsed = parse(&input); - match &parsed[..] { + match &input[..] { [Value::App(_, _)] => (), - _ => panic!("Expected symbol, got {:?}", parsed), + _ => panic!("Expected symbol, got {:?}", input), } } @@ -696,12 +699,11 @@ mod app_tests { let (input, _) = client.generate_expr(); - let parsed = parse(&input); - match &parsed[..] { + match &input[..] { [Value::App(_, _)] => (), [Value::Sym(_)] => (), [Value::Num(_)] => (), - _ => panic!("Expected symbol, got {:?}", parsed), + _ => panic!("Expected symbol, got {:?}", input), } } @@ -712,10 +714,9 @@ mod app_tests { let (input, _) = client.generate_expr(); - let parsed = parse(&input); - match &parsed[..] { + match &input[..] { [Value::Lam(_, _)] => (), - _ => panic!("Expected symbol, got {:?}", parsed), + _ => panic!("Expected symbol, got {:?}", input), } } @@ -726,10 +727,9 @@ mod app_tests { let (input, _) = client.generate_expr(); - let parsed = parse(&input); - match &parsed[..] { + match &input[..] { [Value::App(t1, _)] if matches!(**t1, Value::Lam(_, _)) => (), - _ => panic!("Expected symbol, got {:?}", parsed), + _ => panic!("Expected symbol, got {:?}", input), } } @@ -740,9 +740,10 @@ mod app_tests { let (input, _) = client.generate_expr(); - let parsed = parse(&input); - if let [Value::App(_, _)] = &parsed[..] { - assert!(input.split(' ').count() >= 2) + if let [Value::App(_, _)] = &input[..] { +// assert!(input.split(' ').count() >= 2) + } else { + panic!("Expected application, got {:?}", input) } } @@ -753,9 +754,7 @@ mod app_tests { let (input, _) = client.generate_expr(); - let parsed = parse(&input); - - assert!(!parsed.is_empty()); + assert!(!input.is_empty()); } #[test] @@ -765,9 +764,7 @@ mod app_tests { let (input, _) = client.generate_expr(); - let parsed = parse(&input); - - assert!(!parsed.is_empty()); + assert!(!input.is_empty()); } #[test] |
