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:
parent
43ef9a618c
commit
4a3aa4a08b
|
@ -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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue