pub fn prevalence_upper_95(sampled_rows: u64, match_count: u64) -> Option<f64> {
if match_count != 0 || sampled_rows == 0 {
return None;
}
Some(3.0 / sampled_rows as f64)
}
pub fn rule_of_three_message(sampled_rows: u64) -> String {
let bound = prevalence_upper_95(sampled_rows, 0).unwrap_or(0.0);
format!(
"0 matches in {sampled_rows} sampled rows; prevalence above {:.1}% is unlikely at 95% confidence.",
bound * 100.0
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn thousand_rows_is_point_three_percent() {
let p = prevalence_upper_95(1000, 0).unwrap();
assert!((p - 0.003).abs() < 1e-12);
let msg = rule_of_three_message(1000);
assert!(msg.contains("0.3%"));
}
}