Add missing Mul impls for amount types
Add and test missing `Mul` impls for both amount types.
This commit is contained in:
parent
501c9ab89e
commit
b57bfb9bc5
|
@ -161,6 +161,16 @@ crate::internal_macros::impl_op_for_references! {
|
|||
|
||||
fn mul(self, rhs: u64) -> Self::Output { self.and_then(|lhs| lhs * rhs) }
|
||||
}
|
||||
impl ops::Mul<Amount> for u64 {
|
||||
type Output = NumOpResult<Amount>;
|
||||
|
||||
fn mul(self, rhs: Amount) -> Self::Output { rhs.checked_mul(self).valid_or_error() }
|
||||
}
|
||||
impl ops::Mul<NumOpResult<Amount>> for u64 {
|
||||
type Output = NumOpResult<Amount>;
|
||||
|
||||
fn mul(self, rhs: NumOpResult<Amount>) -> Self::Output { rhs.and_then(|rhs| self * rhs) }
|
||||
}
|
||||
|
||||
impl ops::Div<u64> for Amount {
|
||||
type Output = NumOpResult<Amount>;
|
||||
|
@ -221,6 +231,16 @@ crate::internal_macros::impl_op_for_references! {
|
|||
|
||||
fn mul(self, rhs: i64) -> Self::Output { self.and_then(|lhs| lhs * rhs) }
|
||||
}
|
||||
impl ops::Mul<SignedAmount> for i64 {
|
||||
type Output = NumOpResult<SignedAmount>;
|
||||
|
||||
fn mul(self, rhs: SignedAmount) -> Self::Output { rhs.checked_mul(self).valid_or_error() }
|
||||
}
|
||||
impl ops::Mul<NumOpResult<SignedAmount>> for i64 {
|
||||
type Output = NumOpResult<SignedAmount>;
|
||||
|
||||
fn mul(self, rhs: NumOpResult<SignedAmount>) -> Self::Output { rhs.and_then(|rhs| self * rhs) }
|
||||
}
|
||||
|
||||
impl ops::Div<i64> for SignedAmount {
|
||||
type Output = NumOpResult<SignedAmount>;
|
||||
|
|
|
@ -1252,8 +1252,10 @@ fn op_int_combos() {
|
|||
assert_eq!(res(23) * 31, res(713));
|
||||
assert_eq!(sres(23) * 31, sres(713));
|
||||
|
||||
// assert_eq!(31 * sat(23), res(713));
|
||||
// assert_eq!(31 * ssat(23), sres(713));
|
||||
assert_eq!(31 * sat(23), res(713));
|
||||
assert_eq!(31 * ssat(23), sres(713));
|
||||
assert_eq!(31 * res(23), res(713));
|
||||
assert_eq!(31 * sres(23), sres(713));
|
||||
|
||||
// No remainder.
|
||||
assert_eq!(sat(1897) / 7, res(271));
|
||||
|
|
Loading…
Reference in New Issue