Tesys for U256 assign ops.

This commit is contained in:
Gav Wood 2016-01-16 16:52:59 +01:00
parent 512eee04cf
commit 0c2869d542

View File

@ -506,6 +506,36 @@ macro_rules! construct_uint {
} }
} }
impl AddAssign<$name> for $name {
fn add_assign(&mut self, other: Self) {
*self = self.add(other);
}
}
impl SubAssign<$name> for $name {
fn sub_assign(&mut self, other: Self) {
*self = self.sub(other);
}
}
impl MulAssign<$name> for $name {
fn mul_assign(&mut self, other: Self) {
*self = self.mul(other);
}
}
impl DivAssign<$name> for $name {
fn div_assign(&mut self, other: Self) {
*self = self.div(other);
}
}
impl RemAssign<$name> for $name {
fn rem_assign(&mut self, other: Self) {
*self = self.rem(other);
}
}
impl BitAnd<$name> for $name { impl BitAnd<$name> for $name {
type Output = $name; type Output = $name;
@ -776,6 +806,37 @@ mod tests {
use std::str::FromStr; use std::str::FromStr;
use std::num::wrapping::OverflowingOps; use std::num::wrapping::OverflowingOps;
#[test]
pub fn assign_ops() {
let x: U256 = x!(69);
let y: U256 = x!(42);
{
let mut z = x;
z += y;
assert_eq!(z, x + y);
}
{
let mut z = x;
z -= y;
assert_eq!(z, x - y);
}
{
let mut z = x;
z *= y;
assert_eq!(z, x * y);
}
{
let mut z = x;
z /= y;
assert_eq!(z, x / y);
}
{
let mut z = x;
z %= y;
assert_eq!(z, x % y);
}
}
#[test] #[test]
pub fn uint256_from() { pub fn uint256_from() {
let e = U256([10, 0, 0, 0]); let e = U256([10, 0, 0, 0]);