use super::CoverageMap;
#[derive(Debug, Clone)]
pub enum SamplingStrategy {
Exhaustive {
max_depth: usize,
},
Random {
seed: u64,
count: usize,
},
CoverageGuided {
coverage_map: Option<CoverageMap>,
max_depth: usize,
seed: u64,
},
Swarm {
features_per_batch: usize,
},
Boundary {
boundary_probability: f64,
},
}
impl Default for SamplingStrategy {
fn default() -> Self {
Self::CoverageGuided {
coverage_map: None,
max_depth: 3,
seed: 42,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_strategy() {
let strategy = SamplingStrategy::default();
assert!(matches!(strategy, SamplingStrategy::CoverageGuided { .. }));
}
#[test]
fn test_exhaustive_strategy() {
let strategy = SamplingStrategy::Exhaustive { max_depth: 5 };
if let SamplingStrategy::Exhaustive { max_depth } = strategy {
assert_eq!(max_depth, 5);
} else {
panic!("Expected Exhaustive strategy");
}
}
#[test]
fn test_boundary_strategy() {
let strategy = SamplingStrategy::Boundary {
boundary_probability: 0.3,
};
if let SamplingStrategy::Boundary {
boundary_probability,
} = strategy
{
assert!((boundary_probability - 0.3).abs() < f64::EPSILON);
} else {
panic!("Expected Boundary strategy");
}
}
#[test]
fn test_random_strategy() {
let strategy = SamplingStrategy::Random {
seed: 42,
count: 100,
};
if let SamplingStrategy::Random { seed, count } = strategy {
assert_eq!(seed, 42);
assert_eq!(count, 100);
} else {
panic!("Expected Random strategy");
}
}
#[test]
fn test_coverage_guided_strategy() {
let strategy = SamplingStrategy::CoverageGuided {
coverage_map: None,
max_depth: 5,
seed: 123,
};
if let SamplingStrategy::CoverageGuided {
max_depth, seed, ..
} = strategy
{
assert_eq!(max_depth, 5);
assert_eq!(seed, 123);
} else {
panic!("Expected CoverageGuided strategy");
}
}
#[test]
fn test_swarm_strategy() {
let strategy = SamplingStrategy::Swarm {
features_per_batch: 10,
};
if let SamplingStrategy::Swarm { features_per_batch } = strategy {
assert_eq!(features_per_batch, 10);
} else {
panic!("Expected Swarm strategy");
}
}
#[test]
fn test_strategy_debug() {
let strategy = SamplingStrategy::Exhaustive { max_depth: 3 };
let debug = format!("{:?}", strategy);
assert!(debug.contains("Exhaustive"));
}
#[test]
fn test_strategy_clone() {
let strategy = SamplingStrategy::Random {
seed: 42,
count: 10,
};
let cloned = strategy.clone();
if let SamplingStrategy::Random { seed, count } = cloned {
assert_eq!(seed, 42);
assert_eq!(count, 10);
} else {
panic!("Expected Random strategy clone");
}
}
}