use super::{zero_progress_stop_reason, IterationReport};
use std::path::PathBuf;
fn report(iteration: usize, tests_generated: usize, coverage_gain: f64) -> IterationReport {
IterationReport {
iteration,
files_targeted: vec![PathBuf::from("src/lib.rs")],
tests_generated,
coverage_gain,
mutation_score: f64::NAN,
}
}
#[test]
fn a_zero_progress_iteration_stops_the_loop() {
let reason = zero_progress_stop_reason(&report(1, 0, 0.0))
.expect("0 tests + 0.00% gain must stop the loop");
assert!(
reason.contains("No progress in iteration 1"),
"stop reason must name the stalled iteration: {reason}"
);
assert!(
reason.contains("0 tests generated"),
"stop reason must state what it observed: {reason}"
);
}
#[test]
fn a_negative_gain_iteration_stops_the_loop() {
assert!(zero_progress_stop_reason(&report(2, 0, -0.5)).is_some());
}
#[test]
fn progress_does_not_stop_the_loop() {
assert!(
zero_progress_stop_reason(&report(1, 0, 1.5)).is_none(),
"coverage rose, so the next iteration is not a repeat"
);
assert!(
zero_progress_stop_reason(&report(1, 3, 0.0)).is_none(),
"tests were written; the next coverage run has new input"
);
}