Add ops unit tests for Weight

Copy the unit tests from `FeeRate` that prove `Add`, `AddAssign`, `Sub`,
and `SubAssign` for references.
This commit is contained in:
Tobin C. Harding 2024-12-11 16:29:05 +11:00
parent 43ef9a618c
commit 4a3aa4a08b
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 48 additions and 0 deletions

View File

@ -357,4 +357,52 @@ mod tests {
#[test] #[test]
fn checked_div_overflows() { assert!(TWO.checked_div(0).is_none()) } 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));
}
} }