moved specific tests to prime_field_arithmetic

This commit is contained in:
Nicholas Ward 2021-07-22 10:55:11 -07:00
parent 1322b8d0d2
commit 5d30124101
4 changed files with 34 additions and 22 deletions

View File

@ -480,7 +480,7 @@ impl Frobenius<1> for CrandallField {}
#[cfg(test)]
mod tests {
use crate::test_arithmetic;
use crate::test_prime_field_arithmetic;
test_arithmetic!(crate::field::crandall_field::CrandallField);
test_prime_field_arithmetic!(crate::field::crandall_field::CrandallField);
}

View File

@ -222,7 +222,7 @@ mod tests {
use crate::field::extension_field::quadratic::QuadraticCrandallField;
use crate::field::extension_field::{FieldExtension, Frobenius};
use crate::field::field::Field;
use crate::test_arithmetic;
use crate::test_field_arithmetic;
#[test]
fn test_add_neg_sub_mul() {
@ -294,5 +294,5 @@ mod tests {
);
}
test_arithmetic!(crate::field::extension_field::quadratic::QuadraticCrandallField);
test_field_arithmetic!(crate::field::extension_field::quadratic::QuadraticCrandallField);
}

View File

@ -289,7 +289,7 @@ mod tests {
use crate::field::extension_field::quartic::QuarticCrandallField;
use crate::field::extension_field::{FieldExtension, Frobenius};
use crate::field::field::Field;
use crate::test_arithmetic;
use crate::test_field_arithmetic;
fn exp_naive<F: Field>(x: F, power: u128) -> F {
let mut current = x;
@ -388,5 +388,5 @@ mod tests {
);
}
test_arithmetic!(crate::field::extension_field::quartic::QuarticCrandallField);
test_field_arithmetic!(crate::field::extension_field::quartic::QuarticCrandallField);
}

View File

@ -149,9 +149,9 @@ pub fn run_binaryop_test_cases<F, BinaryOp, ExpectedOp>(
}
#[macro_export]
macro_rules! test_arithmetic {
macro_rules! test_prime_field_arithmetic {
($field:ty) => {
mod arithmetic {
mod prime_field_arithmetic {
use std::ops::{Add, Mul, Neg, Sub};
use num_bigint::BigUint;
@ -161,7 +161,7 @@ macro_rules! test_arithmetic {
// Can be 32 or 64; doesn't have to be computer's actual word
// bits. Choosing 32 gives more tests...
const WORD_BITS: usize = 32;
#[test]
fn arithmetic_addition() {
let modulus = <$field>::order();
@ -251,6 +251,30 @@ macro_rules! test_arithmetic {
}
}
#[test]
fn subtraction() {
type F = $field;
let (a, b) = (
F::from_canonical_biguint((F::order() + 1u32) / 2u32),
F::TWO,
);
let x = a * b;
assert_eq!(x, F::ONE);
assert_eq!(F::ZERO - x, F::NEG_ONE);
}
}
};
}
#[macro_export]
macro_rules! test_field_arithmetic {
($field:ty) => {
mod field_arithmetic {
use num_bigint::BigUint;
use crate::field::field::Field;
#[test]
fn batch_inversion() {
let xs = (1..=3)
@ -322,19 +346,6 @@ macro_rules! test_arithmetic {
}
}
#[test]
fn subtraction() {
type F = $field;
let (a, b) = (
F::from_canonical_biguint((F::order() + 1u32) / 2u32),
F::TWO,
);
let x = a * b;
assert_eq!(x, F::ONE);
assert_eq!(F::ZERO - x, F::NEG_ONE);
}
#[test]
fn inverse_2exp() {
// Just check consistency with try_inverse()
@ -351,3 +362,4 @@ macro_rules! test_arithmetic {
}
};
}