Skip to content

Commit

Permalink
Optional #iterations in group & field tests (#766)
Browse files Browse the repository at this point in the history
* enable specifying a custom number of iterations for testing

* decrease iterations for mnt6_753

* fix macros

* decrease iterations for mnt4-753

* decrease iters further

* Update test-templates/src/fields.rs
  • Loading branch information
mmagician authored Jan 31, 2024
1 parent 228787b commit 1ad034f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
6 changes: 3 additions & 3 deletions curves/mnt4_753/src/curves/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::*;
use ark_algebra_test_templates::*;

test_group!(g1; G1Projective; sw);
test_group!(g2; G2Projective; sw);
test_group!(pairing_output; ark_ec::pairing::PairingOutput<MNT4_753>; msm);
test_group!(50; g1; G1Projective; sw);
test_group!(50; g2; G2Projective; sw);
test_group!(50; pairing_output; ark_ec::pairing::PairingOutput<MNT4_753>; msm);
test_pairing!(pairing; crate::MNT4_753);
8 changes: 4 additions & 4 deletions curves/mnt4_753/src/fields/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::*;
use ark_algebra_test_templates::*;

test_field!(fr; Fr; mont_prime_field);
test_field!(fq; Fq; mont_prime_field);
test_field!(fq2; Fq2);
test_field!(fq4; Fq4);
test_field!(100; fr; Fr; mont_prime_field);
test_field!(100; fq; Fq; mont_prime_field);
test_field!(100; fq2; Fq2);
test_field!(100; fq4; Fq4);
6 changes: 3 additions & 3 deletions curves/mnt6_753/src/curves/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::*;
use ark_algebra_test_templates::*;

test_group!(g1; G1Projective; sw);
test_group!(g2; G2Projective; sw);
test_group!(pairing_output; ark_ec::pairing::PairingOutput<MNT6_753>; msm);
test_group!(50; g1; G1Projective; sw);
test_group!(50; g2; G2Projective; sw);
test_group!(50; pairing_output; ark_ec::pairing::PairingOutput<MNT6_753>; msm);
test_pairing!(pairing; crate::MNT6_753);
8 changes: 4 additions & 4 deletions curves/mnt6_753/src/fields/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use ark_algebra_test_templates::*;
use ark_ff::fields::{models::fp6_2over3::*, quadratic_extension::QuadExtConfig};
use ark_std::{rand::Rng, test_rng};

test_field!(fr; Fr; mont_prime_field);
test_field!(fq; Fq; mont_prime_field);
test_field!(fq3; Fq3);
test_field!(fq6; Fq6);
test_field!(100; fr; Fr; mont_prime_field);
test_field!(100; fq; Fq; mont_prime_field);
test_field!(100; fq3; Fq3);
test_field!(100; fq6; Fq6);

#[test]
fn test_fq3_more() {
Expand Down
17 changes: 16 additions & 1 deletion test-templates/src/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ macro_rules! __test_field {

#[macro_export]
macro_rules! test_field {
($mod_name: ident; $field: ty $(; $tail:tt)*) => {
($mod_name:ident; $field:ty $(; $tail:tt)*) => {
mod $mod_name {
use super::*;
use ark_ff::{
Expand All @@ -542,4 +542,19 @@ macro_rules! test_field {
$crate::__test_field!($field $(; $tail)*);
}
};

($iters:expr; $mod_name:ident; $field:ty $(; $tail:tt)*) => {
mod $mod_name {
use super::*;
use ark_ff::{
fields::{FftField, Field, LegendreSymbol, PrimeField},
Fp, MontBackend, MontConfig,
};
use ark_serialize::{buffer_bit_byte_size, Flags};
use ark_std::{io::Cursor, rand::Rng, vec::Vec, test_rng, vec, Zero, One, UniformRand};
const ITERATIONS: usize = $iters;

$crate::__test_field!($field $(; $tail)*);
}
};
}
15 changes: 14 additions & 1 deletion test-templates/src/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ macro_rules! __test_group {

#[macro_export]
macro_rules! test_group {
($mod_name: ident; $group: ty $(; $tail:tt)*) => {
($mod_name:ident; $group:ty $(; $tail:tt)* ) => {
mod $mod_name {
use super::*;
use ark_ff::*;
Expand All @@ -417,4 +417,17 @@ macro_rules! test_group {
$crate::__test_group!($group $(; $tail)*);
}
};

($iters:expr; $mod_name:ident; $group:ty $(; $tail:tt)* ) => {
mod $mod_name {
use super::*;
use ark_ff::*;
use ark_ec::{PrimeGroup, CurveGroup, ScalarMul, AffineRepr, CurveConfig, short_weierstrass::SWCurveConfig, twisted_edwards::TECurveConfig, scalar_mul::{*, wnaf::*}};
use ark_serialize::*;
use ark_std::{io::Cursor, rand::Rng, vec::Vec, test_rng, vec, Zero, One, UniformRand};
const ITERATIONS: usize = $iters;

$crate::__test_group!($group $(; $tail)*);
}
};
}

0 comments on commit 1ad034f

Please sign in to comment.