Skip to content

Commit

Permalink
MVPoly: move test_is_constant in pbt and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
dannywillems committed Oct 15, 2024
1 parent 8b10238 commit 9eff145
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 36 deletions.
30 changes: 30 additions & 0 deletions mvpoly/src/pbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,33 @@ pub fn test_is_multilinear<F: PrimeField, const N: usize, const D: usize, T: MVP
assert!(!p.is_multilinear());
}
}

pub fn test_is_constant<F: PrimeField, const N: usize, const D: usize, T: MVPoly<F, N, D>>() {
let mut rng = o1_utils::tests::make_test_rng(None);
let c = F::rand(&mut rng);
let p = T::from(c);
assert!(p.is_constant());

let p = T::zero();
assert!(p.is_constant());

let p = {
let mut res = T::zero();
let monomial: [usize; N] = std::array::from_fn(|i| if i == 0 { 1 } else { 0 });
res.add_monomial(monomial, F::one());
res
};
assert!(!p.is_constant());

let p = {
let mut res = T::zero();
let monomial: [usize; N] = std::array::from_fn(|i| if i == 1 { 1 } else { 0 });
res.add_monomial(monomial, F::one());
res
};
assert!(!p.is_constant());

// This might be flaky
let p = unsafe { T::random(&mut rng, None) };
assert!(!p.is_constant());
}
12 changes: 1 addition & 11 deletions mvpoly/tests/monomials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,7 @@ fn test_degree_random_degree() {

#[test]
fn test_is_constant() {
let mut rng = o1_utils::tests::make_test_rng(None);
let c = Fp::rand(&mut rng);
let p = Sparse::<Fp, 4, 5>::from(c);
assert!(p.is_constant());

let p = Sparse::<Fp, 4, 5>::zero();
assert!(p.is_constant());

// This might be flaky
let p = unsafe { Sparse::<Fp, 4, 5>::random(&mut rng, None) };
assert!(!p.is_constant());
mvpoly::pbt::test_is_constant::<Fp, 4, 5, Sparse<Fp, 4, 5>>();
}

#[test]
Expand Down
26 changes: 1 addition & 25 deletions mvpoly/tests/prime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,31 +555,7 @@ fn test_degree_random_degree() {

#[test]
fn test_is_constant() {
let mut rng = o1_utils::tests::make_test_rng(None);
let c = Fp::rand(&mut rng);
let p = Dense::<Fp, 4, 5>::from(c);
assert!(p.is_constant());

let p = Dense::<Fp, 4, 5>::zero();
assert!(p.is_constant());

let p = {
let mut res = Dense::<Fp, 4, 5>::zero();
res.add_monomial([1, 0, 0, 0], Fp::one());
res
};
assert!(!p.is_constant());

let p = {
let mut res = Dense::<Fp, 4, 5>::zero();
res.add_monomial([0, 1, 0, 0], Fp::one());
res
};
assert!(!p.is_constant());

// This might be flaky
let p = unsafe { Dense::<Fp, 4, 5>::random(&mut rng, None) };
assert!(!p.is_constant());
mvpoly::pbt::test_is_constant::<Fp, 4, 5, Dense<Fp, 4, 5>>();
}

#[test]
Expand Down

0 comments on commit 9eff145

Please sign in to comment.