Tesys for U256 assign ops.
This commit is contained in:
parent
512eee04cf
commit
0c2869d542
61
src/uint.rs
61
src/uint.rs
@ -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 {
|
||||
type Output = $name;
|
||||
|
||||
@ -776,6 +806,37 @@ mod tests {
|
||||
use std::str::FromStr;
|
||||
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]
|
||||
pub fn uint256_from() {
|
||||
let e = U256([10, 0, 0, 0]);
|
||||
|
Loading…
Reference in New Issue
Block a user