Skip to main content

Module shrinking

Module shrinking 

Source
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 case

Structs§

CascadingShrinker
Cascading shrinker that applies multiple shrinking strategies in sequence
ConfigurableShrinker
Configurable shrinker with search strategy control
DeltaDebugIterator
Iterator that yields shrinking steps
DeltaDebugShrinker
Delta debugging shrinker for finding minimal failing subsets
GuidedShrinker
Guided shrinker that uses test feedback to prioritize shrinking directions
TargetedShrinkIterator
Iterator for targeted shrinking
TargetedShrinker
Shrinker that shrinks toward a specific target value

Enums§

ShrinkStrategy
Search strategy for shrinking

Traits§

SmartShrink
Trait for shrinking values while preserving invariants