Skip to content

Commit

Permalink
Unit test for FieldVar::double_in_place
Browse files Browse the repository at this point in the history
  • Loading branch information
mskrzypkows committed Mar 21, 2024
1 parent 985bd37 commit 294e89d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/arithmetic_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,29 @@ fn multiplication_test<TargetF: PrimeField, BaseField: PrimeField, R: RngCore>(
);
}

fn doubling_test<TargetF: PrimeField, BaseField: PrimeField, R: RngCore>(
cs: ConstraintSystemRef<BaseField>,
rng: &mut R,
) {
let mut a_native = TargetF::rand(rng);
let mut a =
EmulatedFpVar::<TargetF, BaseField>::new_witness(ark_relations::ns!(cs, "alloc a"), || {
Ok(a_native)
})
.unwrap();

a.double_in_place().unwrap();
a_native.double_in_place();
let a_actual = a.value().unwrap();

assert!(
a_actual.eq(&a_native),
"a_actual = {:?}, a_native = {:?}",
a_actual.into_bigint().as_ref(),
a_native.into_bigint().as_ref()
);
}

fn equality_test<TargetF: PrimeField, BaseField: PrimeField, R: RngCore>(
cs: ConstraintSystemRef<BaseField>,
rng: &mut R,
Expand Down Expand Up @@ -592,6 +615,12 @@ macro_rules! nonnative_test {
$test_target_field,
$test_base_field
);
nonnative_test_individual!(
doubling_test,
$test_name,
$test_target_field,
$test_base_field
);
nonnative_test_individual!(
equality_test,
$test_name,
Expand Down

0 comments on commit 294e89d

Please sign in to comment.