diff --git a/units/src/weight.rs b/units/src/weight.rs index 4191c18ea..9c8b9d8a6 100644 --- a/units/src/weight.rs +++ b/units/src/weight.rs @@ -357,4 +357,52 @@ mod tests { #[test] fn checked_div_overflows() { assert!(TWO.checked_div(0).is_none()) } + + #[test] + #[allow(clippy::op_ref)] + fn addition() { + let one = Weight(1); + let two = Weight(2); + let three = Weight(3); + + assert!(one + two == three); + assert!(&one + two == three); + assert!(one + &two == three); + assert!(&one + &two == three); + } + + #[test] + #[allow(clippy::op_ref)] + fn subtract() { + let one = Weight(1); + let two = Weight(2); + let three = Weight(3); + + assert!(three - two == one); + assert!(&three - two == one); + assert!(three - &two == one); + assert!(&three - &two == one); + } + + #[test] + fn add_assign() { + let mut f = Weight(1); + f += Weight(2); + assert_eq!(f, Weight(3)); + + let mut f = Weight(1); + f += &Weight(2); + assert_eq!(f, Weight(3)); + } + + #[test] + fn sub_assign() { + let mut f = Weight(3); + f -= Weight(2); + assert_eq!(f, Weight(1)); + + let mut f = Weight(3); + f -= &Weight(2); + assert_eq!(f, Weight(1)); + } }