diff options
| author | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-10-06 21:11:04 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-10-06 21:11:04 +0200 |
| commit | a2220cd6ca103b636567b557d21ab345c6ab99e0 (patch) | |
| tree | 6bb4e35c3921d4918a0c7995762bc0b720e40d78 /rust/src/lambda.rs | |
| parent | aaaee7bdc476f5f0631dc0d2f367c54bdfe03d12 (diff) | |
| download | lambda-nantes-a2220cd6ca103b636567b557d21ab345c6ab99e0.tar.gz | |
Use proptest's Strategy to generate expressions
Diffstat (limited to 'rust/src/lambda.rs')
| -rw-r--r-- | rust/src/lambda.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/rust/src/lambda.rs b/rust/src/lambda.rs index d1ab5b5..9b7045f 100644 --- a/rust/src/lambda.rs +++ b/rust/src/lambda.rs @@ -1,3 +1,8 @@ +use proptest::{ + arbitrary::{any, any_with, arbitrary_with}, + strategy::{Strategy, ValueTree}, + test_runner::TestRunner, +}; use rand::{rngs::SmallRng, Rng, RngCore, SeedableRng}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -98,12 +103,13 @@ fn gensym() -> String { format!("x_{}", n1) } -pub fn generate_expr<R: Rng>(size: u32, rng: &mut R) -> Value { +pub fn generate_expr(size: u32, runner: &mut TestRunner) -> Value { match size { 0 | 1 => { - let n: u16 = rng.gen(); + let n = any::<u16>().new_tree(runner).unwrap().current(); Value::Num(n.into()) } + 2 => Value::Sym(identifier().new_tree(runner).unwrap().current()), _ => todo!(), } } |
