summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Bailly <arnaud.bailly@iohk.io>2024-10-09 15:27:29 +0200
committerArnaud Bailly <arnaud.bailly@iohk.io>2024-10-09 15:27:29 +0200
commit2d64cfbafc81cc92bcca3fe758391fb94e5fea9f (patch)
treee48e7047b7e79564b5d080eb17ef90b77d9c3053
parent8d61fb9ca076f481850425f4424469acbb1afe7c (diff)
downloadlambda-nantes-2d64cfbafc81cc92bcca3fe758391fb94e5fea9f.tar.gz
Use 32 bits seed for generating terms
-rw-r--r--rust/src/lambda.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/rust/src/lambda.rs b/rust/src/lambda.rs
index 3a8372b..8ac3e46 100644
--- a/rust/src/lambda.rs
+++ b/rust/src/lambda.rs
@@ -117,7 +117,7 @@ pub fn generate_expr(size: u32, runner: &mut TestRunner) -> Value {
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(),
- 9 => any::<u16>()
+ 9 => any::<u32>()
.prop_flat_map(gen_terms)
.new_tree(runner)
.unwrap()
@@ -162,14 +162,16 @@ fn app_to_lambda() -> impl Strategy<Value = Value> {
(lam, arg).prop_map(|(l, a)| Value::App(Box::new(l), Box::new(a)))
}
-fn pairing(k: u16) -> (u16, u16) {
- let a = ((((8 * (k as u32) + 1) as f32).sqrt() - 1.0) / 2.0).floor();
+/// Cantor pairing function
+/// See https://en.wikipedia.org/wiki/Pairing_function
+fn pairing(k: u32) -> (u32, u32) {
+ let a = ((((8 * (k as u64) + 1) as f64).sqrt() - 1.0) / 2.0).floor();
let b = (a * (a + 1.0)) / 2.0;
- let n = (k as f32) - b;
- (n as u16, (a - n) as u16)
+ let n = (k as f64) - b;
+ (n as u32, (a - n) as u32)
}
-fn gen_terms(u: u16) -> impl Strategy<Value = Value> {
+fn gen_terms(u: u32) -> impl Strategy<Value = Value> {
if u % 2 != 0 {
let j = (u - 1) / 2;
if j % 2 == 0 {