most complete carry test ever

This commit is contained in:
Nikolay Volf 2016-02-27 18:43:38 +03:00
parent e3c8c99583
commit dc604c21b5

View File

@ -1537,6 +1537,76 @@ mod tests {
assert_eq!(U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, 0]), result); assert_eq!(U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, 0]), result);
} }
#[test]
fn u256_multi_carry_all() {
let (result, _) = U256([::std::u64::MAX, 0, 0, 0]).overflowing_mul(U256([::std::u64::MAX, 0, 0, 0]));
assert_eq!(U256([1, ::std::u64::MAX-1, 0, 0]), result);
let (result, _) = U256([0, ::std::u64::MAX, 0, 0]).overflowing_mul(U256([::std::u64::MAX, 0, 0, 0]));
assert_eq!(U256([0, 1, ::std::u64::MAX-1, 0]), result);
let (result, _) = U256([::std::u64::MAX, ::std::u64::MAX, 0, 0]).overflowing_mul(U256([::std::u64::MAX, 0, 0, 0]));
assert_eq!(U256([1, ::std::u64::MAX, ::std::u64::MAX-1, 0]), result);
let (result, _) = U256([::std::u64::MAX, 0, 0, 0]).overflowing_mul(U256([::std::u64::MAX, ::std::u64::MAX, 0, 0]));
assert_eq!(U256([1, ::std::u64::MAX, ::std::u64::MAX-1, 0]), result);
let (result, _) = U256([::std::u64::MAX, ::std::u64::MAX, 0, 0])
.overflowing_mul(U256([::std::u64::MAX, ::std::u64::MAX, 0, 0]));
assert_eq!(U256([1, 0, ::std::u64::MAX-1, ::std::u64::MAX]), result);
let (result, _) = U256([::std::u64::MAX, 0, 0, 0]).overflowing_mul(U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, 0]));
assert_eq!(U256([1, ::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX-1]), result);
let (result, _) = U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, 0]).overflowing_mul(U256([::std::u64::MAX, 0, 0, 0]));
assert_eq!(U256([1, ::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX-1]), result);
let (result, _) = U256([::std::u64::MAX, 0, 0, 0]).overflowing_mul(
U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX]));
assert_eq!(U256([1, ::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX]), result);
let (result, _) = U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX])
.overflowing_mul(U256([::std::u64::MAX, 0, 0, 0]));
assert_eq!(U256([1, ::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX]), result);
let (result, _) = U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, 0])
.overflowing_mul(U256([::std::u64::MAX, ::std::u64::MAX, 0, 0]));
assert_eq!(U256([1, 0, ::std::u64::MAX, ::std::u64::MAX-1]), result);
let (result, _) = U256([::std::u64::MAX, ::std::u64::MAX, 0, 0])
.overflowing_mul(U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, 0]));
assert_eq!(U256([1, 0, ::std::u64::MAX, ::std::u64::MAX-1]), result);
let (result, _) = U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX])
.overflowing_mul(U256([::std::u64::MAX, ::std::u64::MAX, 0, 0]));
assert_eq!(U256([1, 0, ::std::u64::MAX, ::std::u64::MAX]), result);
let (result, _) = U256([::std::u64::MAX, ::std::u64::MAX, 0, 0])
.overflowing_mul(U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX]));
assert_eq!(U256([1, 0, ::std::u64::MAX, ::std::u64::MAX]), result);
let (result, _) = U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, 0])
.overflowing_mul(U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, 0]));
assert_eq!(U256([1, 0, 0, ::std::u64::MAX-1]), result);
let (result, _) = U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, 0])
.overflowing_mul(U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX]));
assert_eq!(U256([1, 0, 0, ::std::u64::MAX]), result);
let (result, _) = U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX])
.overflowing_mul(U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, 0]));
assert_eq!(U256([1, 0, 0, ::std::u64::MAX]), result);
let (result, _) = U256([0, 0, 0, ::std::u64::MAX]).overflowing_mul(U256([0, 0, 0, ::std::u64::MAX]));
assert_eq!(U256([0, 0, 0, 0]), result);
let (result, _) = U256([1, 0, 0, 0]).overflowing_mul(U256([0, 0, 0, ::std::u64::MAX]));
assert_eq!(U256([0, 0, 0, ::std::u64::MAX]), result);
let (result, _) = U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX])
.overflowing_mul(U256([::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX, ::std::u64::MAX]));
assert_eq!(U256([1, 0, 0, 0]), result);
}
#[test] #[test]
fn u256_multi_muls() { fn u256_multi_muls() {