Old Fuzzer, new Sampler

This commit is contained in:
Riley-Kilgore
2024-12-17 06:01:19 -08:00
committed by Riley
parent c0fabcd26a
commit 84a0abeb0f
14 changed files with 164 additions and 127 deletions

View File

@@ -193,7 +193,7 @@ impl Error {
test.input_path.to_path_buf(),
test.program.to_pretty(),
),
TestResult::Benchmark(_) => ("benchmark".to_string(), PathBuf::new(), String::new()), // todo
TestResult::Benchmark(_) => ("bench".to_string(), PathBuf::new(), String::new()), // todo
};
Error::TestFailure {

View File

@@ -112,10 +112,8 @@ mod test {
const max_int: Int = 255
pub type Fuzzer<a> = Generator<Void, a>
pub fn int() -> Fuzzer<Int> {
fn(v: Void, prng: PRNG) -> Option<(PRNG, Int)> {
fn(prng: PRNG) -> Option<(PRNG, Int)> {
when prng is {
Seeded { seed, choices } -> {
let choice =
@@ -163,21 +161,21 @@ mod test {
}
pub fn constant(a: a) -> Fuzzer<a> {
fn(v, s0) { Some((s0, a)) }
fn(s0) { Some((s0, a)) }
}
pub fn and_then(fuzz_a: Fuzzer<a>, f: fn(a) -> Fuzzer<b>) -> Fuzzer<b> {
fn(v, s0) {
when fuzz_a(v, s0) is {
Some((s1, a)) -> f(a)(v, s1)
fn(s0) {
when fuzz_a(s0) is {
Some((s1, a)) -> f(a)(s1)
None -> None
}
}
}
pub fn map(fuzz_a: Fuzzer<a>, f: fn(a) -> b) -> Fuzzer<b> {
fn(v, s0) {
when fuzz_a(v, s0) is {
fn(s0) {
when fuzz_a(s0) is {
Some((s1, a)) -> Some((s1, f(a)))
None -> None
}
@@ -185,10 +183,10 @@ mod test {
}
pub fn map2(fuzz_a: Fuzzer<a>, fuzz_b: Fuzzer<b>, f: fn(a, b) -> c) -> Fuzzer<c> {
fn(v, s0) {
when fuzz_a(v, s0) is {
fn(s0) {
when fuzz_a(s0) is {
Some((s1, a)) ->
when fuzz_b(Void, s1) is {
when fuzz_b(s1) is {
Some((s2, b)) -> Some((s2, f(a, b)))
None -> None
}