From 24cc059a78648fd6412dc84c8734c16ddf130cb4 Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Tue, 20 May 2025 16:04:59 +0100 Subject: [PATCH] Add tests to result New mutants found in weekly mutation testing. Add tests to kill them. --- units/src/result.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/units/src/result.rs b/units/src/result.rs index f0587b2b2..1685778ae 100644 --- a/units/src/result.rs +++ b/units/src/result.rs @@ -311,3 +311,34 @@ impl fmt::Display for MathOp { } } } + +#[cfg(test)] +mod tests { + use crate::MathOp; + + #[test] + fn mathop_predicates() { + assert!(MathOp::Add.is_overflow()); + assert!(MathOp::Sub.is_overflow()); + assert!(MathOp::Mul.is_overflow()); + assert!(MathOp::Neg.is_overflow()); + assert!(!MathOp::Div.is_overflow()); + assert!(!MathOp::Rem.is_overflow()); + + assert!(MathOp::Div.is_div_by_zero()); + assert!(MathOp::Rem.is_div_by_zero()); + assert!(!MathOp::Add.is_div_by_zero()); + + assert!(MathOp::Add.is_addition()); + assert!(!MathOp::Sub.is_addition()); + + assert!(MathOp::Sub.is_subtraction()); + assert!(!MathOp::Add.is_subtraction()); + + assert!(MathOp::Mul.is_multiplication()); + assert!(!MathOp::Div.is_multiplication()); + + assert!(MathOp::Neg.is_negation()); + assert!(!MathOp::Add.is_negation()); + } +}