use super::PolynomialRingZq;
use crate::integer_mod_q::{NTTPolynomialRingZq, PolyOverZq};
impl PolynomialRingZq {
pub fn is_irreducible(&self) -> bool {
let poly_over_zq = PolyOverZq::from((&self.poly, self.modulus.get_q()));
poly_over_zq.is_irreducible()
}
pub fn is_one(&self) -> bool {
self.poly.is_one()
}
pub fn is_zero(&self) -> bool {
self.poly.is_zero()
}
pub fn ntt(&self) -> NTTPolynomialRingZq {
NTTPolynomialRingZq::from(self)
}
}
#[cfg(test)]
mod test_is_irreducible {
use crate::integer_mod_q::PolynomialRingZq;
use std::str::FromStr;
#[test]
fn poly_is_irreducible() {
let poly_irr = PolynomialRingZq::from_str("3 10 12 9 / 4 1 10 12 1 mod 17").unwrap();
assert!(poly_irr.is_irreducible());
}
#[test]
fn poly_is_reducible() {
let poly_irr = PolynomialRingZq::from_str("3 1 2 1 / 4 1 10 12 1 mod 17").unwrap();
assert!(!poly_irr.is_irreducible());
}
}
#[cfg(test)]
mod test_is_one {
use super::PolynomialRingZq;
use std::str::FromStr;
#[test]
fn one_detection() {
let one = PolynomialRingZq::from_str("1 1 / 4 1 10 12 1 mod 7").unwrap();
let one_2 = PolynomialRingZq::from_str("2 1 14 / 4 1 10 12 1 mod 7").unwrap();
assert!(one.is_one());
assert!(one_2.is_one());
}
#[test]
fn one_rejection() {
let small = PolynomialRingZq::from_str("4 1 0 0 1 / 4 1 10 12 1 mod 7").unwrap();
let large = PolynomialRingZq::from_str(&format!(
"1 {} / 4 1 10 12 1 mod {}",
(u128::MAX - 1) / 2 + 2,
u128::MAX
)) .unwrap();
assert!(!small.is_one());
assert!(!large.is_one());
}
}
#[cfg(test)]
mod test_is_zero {
use super::PolynomialRingZq;
use std::str::FromStr;
#[test]
fn zero_detection() {
let zero = PolynomialRingZq::from_str("0 / 2 1 1 mod 7").unwrap();
let zero_2 = PolynomialRingZq::from_str("2 7 14 / 2 1 1 mod 7").unwrap();
let zero_3 = PolynomialRingZq::from_str("3 3 3 3 / 3 1 1 1 mod 11").unwrap();
assert!(zero.is_zero());
assert!(zero_2.is_zero());
assert!(zero_3.is_zero());
}
#[test]
fn zero_rejection() {
let small = PolynomialRingZq::from_str("4 0 0 0 1 / 2 1 1 mod 7").unwrap();
let large = PolynomialRingZq::from_str(&format!(
"1 {} / 2 1 1 mod {}",
(u128::MAX - 1) / 2 + 1,
u128::MAX
)) .unwrap();
assert!(!small.is_zero());
assert!(!large.is_zero());
}
}