Expand description
Enhanced shrinking strategies for Protest
This module provides advanced shrinking strategies that go beyond basic shrinking:
- Smart Shrinking: Preserve invariants while shrinking
- Delta Debugging: Binary search for minimal failing subsets
- Targeted Shrinking: Shrink toward specific target values
§Examples
§Smart Shrinking with Invariants
use protest_extras::shrinking::SmartShrink;
let mut sorted_vec = vec![1, 3, 5, 7, 9];
// Shrink while keeping the vector sorted
let shrunk = sorted_vec.shrink_preserving(|v| {
v.windows(2).all(|w| w[0] <= w[1])
});
for candidate in shrunk {
// All candidates remain sorted
assert!(candidate.windows(2).all(|w| w[0] <= w[1]));
}§Delta Debugging
use protest_extras::shrinking::DeltaDebugShrinker;
let operations = vec![1, 2, 3, 4, 5, 6, 7, 8];
// Find minimal subset that fails a test
let shrinker = DeltaDebugShrinker::new(operations);
let minimal = shrinker.find_minimal(|ops| {
// Only fails if contains both 3 and 7
ops.contains(&3) && ops.contains(&7)
});
assert_eq!(minimal, vec![3, 7]); // Minimal failing caseStructs§
- Cascading
Shrinker - Cascading shrinker that applies multiple shrinking strategies in sequence
- Configurable
Shrinker - Configurable shrinker with search strategy control
- Delta
Debug Iterator - Iterator that yields shrinking steps
- Delta
Debug Shrinker - Delta debugging shrinker for finding minimal failing subsets
- Guided
Shrinker - Guided shrinker that uses test feedback to prioritize shrinking directions
- Targeted
Shrink Iterator - Iterator for targeted shrinking
- Targeted
Shrinker - Shrinker that shrinks toward a specific target value
Enums§
- Shrink
Strategy - Search strategy for shrinking
Traits§
- Smart
Shrink - Trait for shrinking values while preserving invariants