INNER CODE UNIT · Rust
test_mod_ops
ZenGo-X/curv · src/arithmetic/mod.rs:267
fn test_mod_ops(ops: Vec<(ModOp, u32)>) {
let mut actual = BigInt::zero();
let mut expected = 0u32;
let module = BigInt::from(u32::MAX) + BigInt::one();
for (op, n) in ops {
let was = expected;
match op {
ModOp::Add => {
actual = BigInt::mod_add(&actual, &BigInt::from(n), &module);
expected = expected.wrapping_add(n);
}
ModOp::Sub => {
actual = BigInt::mod_sub(&actual, &BigInt::from(n), &module);
expected = expected.wrapping_sub(n);
}
ModOp::Mul => {
actual = BigInt::mod_mul(&actual, &BigInt::from(n), &module);