https://github.com/alpaylan/crabcheck
A WIP property-based testing library in Rust, built with generalized targeted-property testing in mind.
https://github.com/alpaylan/crabcheck
Last synced: 5 months ago
JSON representation
A WIP property-based testing library in Rust, built with generalized targeted-property testing in mind.
- Host: GitHub
- URL: https://github.com/alpaylan/crabcheck
- Owner: alpaylan
- License: mit
- Created: 2024-03-26T15:44:59.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-07-25T21:33:53.000Z (6 months ago)
- Last Synced: 2025-07-26T04:45:39.363Z (6 months ago)
- Language: Rust
- Size: 33.2 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Crabcheck
A WIP property-based testing library in Rust, built with generalized targeted-property testing in
mind.
## What is property-based testing?
TODO
## Example usage
```rust
use crabcheck::quickcheck::quickcheck;
fn correct_insertion_sort(arr: &mut [i32]) {
for i in 1..arr.len() {
let mut j = i;
while j > 0 && arr[j - 1] > arr[j] {
arr.swap(j - 1, j);
j -= 1;
}
}
}
fn bugged_insertion_sort(arr: &mut [i32]) {
for i in 1..arr.len() - 1 {
let mut j = i;
while j > 0 && arr[j - 1] > arr[j] {
arr.swap(j - 1, j);
j -= 1;
}
}
}
fn is_sorted(array: &[i32]) -> bool {
array.windows(2).all(|window| window[0] <= window[1])
}
fn main() {
let should_work = quickcheck(|input: &mut Vec| {
correct_insertion_sort(input);
is_sorted(input)
});
assert!(should_work.counterexample.is_none());
let should_fail = quickcheck(|input: &mut Vec| {
bugged_insertion_sort(input);
is_sorted(input)
});
assert!(should_fail.counterexample.is_some());
println!(
"Counterexample that doesn't work on buggy implementation: {:?}",
should_fail.counterexample.unwrap(),
);
}
```