Skip to content

Commit

Permalink
Update fuzz to support new stdlib.
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed Aug 29, 2024
1 parent 5936af0 commit 3f5e5dd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: aiken-lang/setup-aiken@v1
with:
version: v1.0.29-alpha
- name: 🧰 Install Aiken
run: cargo install --verbose --git https://github.com/aiken-lang/aiken.git
- run: aiken fmt --check
- run: aiken check -D
- run: aiken build
Expand Down
5 changes: 3 additions & 2 deletions aiken.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions aiken.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "aiken-lang/fuzz"
version = "1.0.0"
version = "2.0.0"
license = "Apache-2.0"
description = "A library for writing Aiken's fuzzers."

Expand All @@ -10,5 +10,5 @@ platform = "github"

[[dependencies]]
name = "aiken-lang/stdlib"
version = "1.9.0"
version = "main"
source = "github"
22 changes: 10 additions & 12 deletions lib/aiken/fuzz.ak
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use aiken/builtin
use aiken/list
use aiken/collection/list
use aiken/math
use aiken/option

Expand Down Expand Up @@ -270,7 +270,7 @@ pub fn set_between(fuzzer: Fuzzer<a>, min: Int, max: Int) -> Fuzzer<List<a>> {
} else {
log2(max - min)
},
nub(100, fuzzer),
nub(100, fuzzer, _),
min,
max,
0,
Expand All @@ -280,17 +280,15 @@ pub fn set_between(fuzzer: Fuzzer<a>, min: Int, max: Int) -> Fuzzer<List<a>> {
}

/// 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!"
fn nub(n: Int, fuzzer: Fuzzer<a>, st: List<a>) -> Fuzzer<a> {
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 list.has(st, a) {
nub(n - 1, fuzzer, st)
} else {
let a <- and_then(fuzzer)
if list.has(st, a) {
nub(n - 1, fuzzer)(st)
} else {
constant(a)
}
constant(a)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/aiken/fuzz.test.ak
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use aiken/bytearray
use aiken/collection/list
use aiken/fuzz.{
and_then, bool, int, int_between, label, list, list_between, list_with_elem,
map, one_of, set, set_between, sublist, such_that,
and_then, bool, int, int_between, label, list_between, list_with_elem, map,
one_of, set, set_between, sublist, such_that,
}
use aiken/list
use aiken/math
use aiken/string
use aiken/primitive/bytearray
use aiken/primitive/string

test prop_int_distribution(n via int()) {
label(
Expand Down Expand Up @@ -118,7 +118,7 @@ test prop_list_with_elem(xs via list_with_elem(int())) {
}

fn list_with_sublist() -> Fuzzer<(List<Int>, List<Int>)> {
let xs <- and_then(list(int()))
let xs <- and_then(fuzz.list(int()))
let sub <- map(sublist(xs))
(xs, sub)
}
Expand Down

0 comments on commit 3f5e5dd

Please sign in to comment.