From 4a3aa4a08b5ff12cb59db0bc6124a65431bc313e Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 11 Dec 2024 16:29:05 +1100 Subject: [PATCH] Add ops unit tests for Weight Copy the unit tests from `FeeRate` that prove `Add`, `AddAssign`, `Sub`, and `SubAssign` for references. --- units/src/weight.rs | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) 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)); + } }