From 8d13b0b70681e228aa7dc7d3a5e8cd63a3f0f594 Mon Sep 17 00:00:00 2001 From: microproofs Date: Thu, 12 Sep 2024 19:06:46 -0400 Subject: [PATCH] Add acceptance test 112 --- examples/acceptance_tests/112/aiken.toml | 9 ++++++ examples/acceptance_tests/112/lib/foo.ak | 36 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 examples/acceptance_tests/112/aiken.toml create mode 100644 examples/acceptance_tests/112/lib/foo.ak diff --git a/examples/acceptance_tests/112/aiken.toml b/examples/acceptance_tests/112/aiken.toml new file mode 100644 index 00000000..fe251634 --- /dev/null +++ b/examples/acceptance_tests/112/aiken.toml @@ -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" diff --git a/examples/acceptance_tests/112/lib/foo.ak b/examples/acceptance_tests/112/lib/foo.ak new file mode 100644 index 00000000..8c15a9de --- /dev/null +++ b/examples/acceptance_tests/112/lib/foo.ak @@ -0,0 +1,36 @@ +pub fn constant(a: a) -> Fuzzer { + fn(s0) { Some((s0, a)) } +} + +pub fn and_then(fuzz_a: Fuzzer, f: fn(a) -> Fuzzer) -> Fuzzer { + 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) -> fn(List) -> Fuzzer { + 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), + ) +}