use crypto_bigint::{const_prime_monty_params, Uint};
use fp::field_ops::FieldOps; use fp::fp_element::FpElement;
const_prime_monty_params!(Fp19Modulus, Uint<1>, "0000000000000013", 2);
type F19 = FpElement<Fp19Modulus, 1>;
#[test]
fn zero_is_zero() {
assert!(bool::from(F19::zero().is_zero()));
}
#[test]
fn one_is_one() {
assert!(bool::from(F19::one().is_one()));
}
#[test]
fn degree_of_base_field_is_one() {
assert_eq!(F19::degree(), 1);
}
#[test]
fn add_mod_p() {
let a = F19::from_u64(17);
let b = F19::from_u64(5);
assert_eq!((a + b).as_limbs()[0], 3);
}
#[test]
fn sub_mod_p() {
let a = F19::from_u64(3);
let b = F19::from_u64(7);
assert_eq!((a - b).as_limbs()[0], 15);
}
#[test]
fn mul_mod_p() {
let a = F19::from_u64(7);
let b = F19::from_u64(8);
assert_eq!((a * b).as_limbs()[0], 18);
}
#[test]
fn neg_mod_p() {
let a = F19::from_u64(3);
assert_eq!((-a).as_limbs()[0], 16);
}
#[test]
fn square() {
let a = F19::from_u64(4);
assert_eq!(a.square().as_limbs()[0], 16);
}
#[test]
fn double() {
let a = F19::from_u64(9);
assert_eq!(a.double().as_limbs()[0], 18);
}
#[test]
fn inv_works() {
let a = F19::from_u64(7);
let inv = a.invert().unwrap();
assert_eq!((a * inv).as_limbs()[0], 1);
}
#[test]
fn inv_zero_is_none() {
assert!(bool::from(F19::zero().invert().is_none()));
}
#[test]
fn characteristic_is_p() {
assert_eq!(F19::characteristic(), vec![19u64]);
}
#[test]
fn pow_works() {
let a = F19::from_u64(2);
assert_eq!(a.pow(&[10]).as_limbs()[0], 17);
}
#[test]
fn legendre_of_qr() {
let a = F19::from_u64(4);
assert_eq!(a.legendre(), 1);
}
#[test]
fn legendre_of_zero() {
assert_eq!(F19::zero().legendre(), 0);
}
#[test]
fn sqrt_of_qr() {
let four = F19::from_u64(4);
let root = four.sqrt().expect("4 is a QR mod 19");
assert_eq!((root * root).as_limbs()[0], 4);
}