google / google/xls

[enhancement] quickcheck constraints

Open
#1,574 7 comments 0 reactions 0 assignees View on GitHub
enhancement testing
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

### What's hard to do? (limit 100 words)

quickcheck works well when the input is constrained naturally by a type. However, oftentimes, I've found a need to constrain the value beyond this type. Quickcheck does not appear to support adding constraints as part of the metadata.

### Current best alternative workaround (limit 100 words)

You can 1) ignore the sample by explicitly returning true for that case, e.g.

https://github.com/google/xls/blob/8c8ad0284fa8475ab5fd5fbda2de03f3950b6002/xls/examples/quickcheck.x#L33

This reduces the number of actual useful samples in the quickcheck.

Or 2) compose the actual value with multiple inputs to satisfy the constraint. This may affect the statistical distribution compared to a properly constrained input.

### Your view of the "best case XLS enhancement" (limit 100 words)

It'd be nice to be able to do:

```
#[quickcheck(constraint="x%2 == 0 && x != 42")]
fn foo(x: u32) -> bool {
```

or similar

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.