#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ClaimOutcome {
Won,
Lost,
}
#[must_use]
pub fn classify_claim(changed: usize) -> ClaimOutcome {
if changed == 1 {
ClaimOutcome::Won
} else {
ClaimOutcome::Lost
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn one_row_changed_wins() {
assert_eq!(classify_claim(1), ClaimOutcome::Won);
}
#[test]
fn zero_rows_lost() {
assert_eq!(classify_claim(0), ClaimOutcome::Lost);
}
#[test]
fn invariant_violation_returns_lost_conservatively() {
for bad in [2usize, 100] {
assert_eq!(
classify_claim(bad),
ClaimOutcome::Lost,
"changed={bad} must be Lost"
);
}
}
#[test]
fn only_exactly_one_produces_won() {
for n in 0usize..=10 {
let outcome = classify_claim(n);
if n == 1 {
assert_eq!(outcome, ClaimOutcome::Won);
} else {
assert_eq!(outcome, ClaimOutcome::Lost);
}
}
}
}