From b17dabefeb3354e8fc85fe641e36fd75909864b6 Mon Sep 17 00:00:00 2001 From: Nicholas Ward Date: Wed, 21 Jul 2021 14:27:30 -0700 Subject: [PATCH] more fixes --- src/field/field_testing.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/field/field_testing.rs b/src/field/field_testing.rs index a86a0587..7fcd1086 100644 --- a/src/field/field_testing.rs +++ b/src/field/field_testing.rs @@ -15,6 +15,7 @@ pub fn test_inputs(modulus: BigUint, word_bits: usize) -> Vec { let smalls: Vec<_> = (0..BIGGEST_SMALL).map(BigUint::from).collect(); // ... and close to MAX: MAX - x let word_max = (BigUint::from(1u32) << word_bits) - 1u32; + let multiple_words_max = (BigUint::from(1u32) << modwords * word_bits) - 1u32; let bigs = smalls.iter().map(|x| &word_max - x).collect(); let one_words = [smalls, bigs].concat(); // For each of the one word inputs above, create a new one at word i. @@ -34,7 +35,7 @@ pub fn test_inputs(modulus: BigUint, word_bits: usize) -> Vec { let diff_max = basic_inputs .iter() .map(|x| x.clone()) - .map(|x| word_max.clone() - x) + .map(|x| multiple_words_max.clone() - x) .filter(|x| x < &modulus) .collect(); // Inputs 'difference from' modulus value @@ -175,10 +176,16 @@ macro_rules! test_arithmetic { fn arithmetic_subtraction() { let modulus = <$field>::order(); crate::field::field_testing::run_binaryop_test_cases( - modulus, + modulus.clone(), WORD_BITS, <$field>::sub, - BigUint::sub, + |x, y| { + if x >= y { + x.clone() - y.clone() + } else { + modulus.clone() - y.clone() + x + } + }, ) } @@ -186,10 +193,16 @@ macro_rules! test_arithmetic { fn arithmetic_negation() { let modulus = <$field>::order(); crate::field::field_testing::run_unaryop_test_cases( - modulus, + modulus.clone(), WORD_BITS, <$field>::neg, - BigUint::neg, + |x| { + if x == BigUint::from(0u32) { + BigUint::from(0u32) + } else { + modulus.clone() - x.clone() + } + }, ) }