Merge rust-bitcoin/rust-bitcoin#4329: units: Add a test to kill mutants in MathOp
ec38860b65
Add a test to kill mutants in MathOp (Jamil Lambert, PhD) Pull request description: Weekly mutation testing found mutants in `is_overflow` and `is_divide_by_zero`. Add a test to kill them. Closes #4310 Closes #4334 ACKs for top commit: tcharding: ACKec38860b65
apoelstra: ACK ec38860b65d01d09bf9189cc1b2d043e4b36a140; successfully ran local tests Tree-SHA512: 05d46d5792cb355d8b79f197bcb397d762c8f5593005589f46b9d085f357d168b767e6deaf30b8bf61434652f9f1db1a09b5f753f30c2e22d7e80450cef61182
This commit is contained in:
commit
e3c5f8cbdf
|
@ -1405,3 +1405,22 @@ fn amount_op_result_sum() {
|
||||||
let _ = amount_refs.iter().copied().sum::<NumOpResult<Amount>>();
|
let _ = amount_refs.iter().copied().sum::<NumOpResult<Amount>>();
|
||||||
let _ = amount_refs.into_iter().sum::<NumOpResult<Amount>>();
|
let _ = amount_refs.into_iter().sum::<NumOpResult<Amount>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn math_op_errors() {
|
||||||
|
let overflow = Amount::MAX + Amount::from_sat(1).unwrap();
|
||||||
|
if let NumOpResult::Error(err) = overflow {
|
||||||
|
assert!(err.operation().is_overflow());
|
||||||
|
assert!(!err.operation().is_div_by_zero());
|
||||||
|
} else {
|
||||||
|
panic!("Expected an overflow error, but got a valid result");
|
||||||
|
}
|
||||||
|
|
||||||
|
let div_by_zero = Amount::from_sat(10).unwrap() / Amount::ZERO;
|
||||||
|
if let NumOpResult::Error(err) = div_by_zero {
|
||||||
|
assert!(!err.operation().is_overflow());
|
||||||
|
assert!(err.operation().is_div_by_zero());
|
||||||
|
} else {
|
||||||
|
panic!("Expected a division by zero error, but got a valid result");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue