Add acceptance test 112

This commit is contained in:
microproofs 2024-09-12 19:06:46 -04:00
parent 362ca2544f
commit 8d13b0b706
No known key found for this signature in database
GPG Key ID: 14F93C84DE6AFD17
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,9 @@
name = "aiken-lang/acceptance_test_111"
version = "0.0.0"
license = "Apache-2.0"
description = "Aiken contracts for project 'aiken-lang/111'"
[repository]
user = "aiken-lang"
project = "112"
platform = "github"

View File

@ -0,0 +1,36 @@
pub fn constant(a: a) -> Fuzzer<a> {
fn(s0) { Some((s0, a)) }
}
pub fn and_then(fuzz_a: Fuzzer<a>, f: fn(a) -> Fuzzer<b>) -> Fuzzer<b> {
fn(s0) {
when fuzz_a(s0) is {
Some((s1, a)) -> f(a)(s1)
None -> None
}
}
}
/// Construct a fuzzer that returns values not present in a given list.
fn nub(n: Int, fuzzer: Fuzzer<a>) -> fn(List<a>) -> Fuzzer<a> {
fn(st) {
if n <= 0 {
fail @"gave up trying to find unique values: the fuzzer did not yield any *new* value after many tries!"
} else {
let a <- and_then(fuzzer)
if False {
nub(n - 1, fuzzer)(st)
} else {
constant(a)
}
}
}
}
test thing() {
let a = 1
nub(2, constant(a))([])(Seeded { seed: #"01", choices: #"" }) == Some(
(Seeded { seed: #"01", choices: #"" }, 1),
)
}