diff --git a/src/tests/polynomials.rs b/src/tests/polynomials.rs index 654eb59..05b71aa 100644 --- a/src/tests/polynomials.rs +++ b/src/tests/polynomials.rs @@ -2,13 +2,21 @@ #[cfg(test)] mod poly_tests { - use crate::{polynomials::*, params::*}; + use crate::{ + polynomials::*, + params::*, + tests::params::params_tests::sec_level_strategy, + }; use proptest::prelude::*; - pub(in crate::tests) fn new_poly_array() -> impl Strategy { + pub(in crate::tests) fn new_limited_poly_array() -> impl Strategy { prop::array::uniform(-(Q as i16)..(Q as i16)) } + pub(in crate::tests) fn new_poly_array() -> impl Strategy { + prop::array::uniform(i16::MIN..i16::MAX) + } + #[test] fn new_test() { let poly = Poly::new(); @@ -20,15 +28,65 @@ mod poly_tests { let poly = Poly::from_arr(&a); } + #[test] + fn add_test( + a in new_limited_poly_array(), + b in new_limited_poly_array() + ) { + let poly_a = Poly::from_arr(&a); + let poly_b = Poly::from_arr(&b); + + let outout = poly_a.add(&poly_b); + } + + #[test] + fn sub_test( + a in new_limited_poly_array(), + b in new_limited_poly_array() + ) { + let poly_a = Poly::from_arr(&a); + let poly_b = Poly::from_arr(&b); + + let outout = poly_a.sub(&poly_b); + } + + #[test] + fn barrett_reduce_test(a in new_poly_array()) { + let poly = Poly::from_arr(&a); + + let output = poly.barrett_reduce(); + } + + #[test] + fn mont_form_test(a in new_poly_array()) { + let poly = Poly::from_arr(&a); + + let output = poly.mont_form(); + } + + #[test] + fn normalise_test(a in new_poly_array()) { + let poly = Poly::from_arr(&a); + + let output = poly.normalise(); + } + #[test] fn pointwise_mul_test( a in new_poly_array(), b in new_poly_array() ) { - let mut poly_a = Poly::from_arr(&a).normalise(); + let poly_a = Poly::from_arr(&a).normalise(); let poly_b = Poly::from_arr(&b).normalise(); - poly_a.pointwise_mul(&poly_b); + let outout = poly_a.pointwise_mul(&poly_b); + } + + #[test] + fn pack_test(a in new_poly_array()) { + let poly = Poly::from_arr(&a).normalise(); + + let output = poly.pack(); } #[test] @@ -37,9 +95,41 @@ mod poly_tests { let msg = poly.write_msg().unwrap(); } + #[test] + fn compress_test( + a in new_poly_array(), + sec_level in sec_level_strategy() + ) { + let mut buf = [0u8; 160]; // max poly_compressed_bytes + let poly = Poly::from_arr(&a).normalise(); + + let result = poly.compress(&mut buf[..sec_level.poly_compressed_bytes()], &sec_level).unwrap(); + } + + #[test] + fn unpack_test(a in new_poly_array()) { + let poly = Poly::from_arr(&a).normalise(); + let buf = poly.pack(); + + let unpacked = Poly::unpack(&buf).unwrap(); + } + #[test] fn read_msg_test(msg in prop::array::uniform32(0u8..)) { let poly = Poly::read_msg(&msg).unwrap(); } + + #[test] + fn decompress_test( + a in new_poly_array(), + sec_level in sec_level_strategy() + ) { + let mut buf = [0u8; 160]; // max poly_compressed_bytes + let poly = Poly::from_arr(&a).normalise(); + + let _ = poly.compress(&mut buf[..sec_level.poly_compressed_bytes()], &sec_level); + + let decompressed_poly = Poly::decompress(&buf[..sec_level.poly_compressed_bytes()], &sec_level).unwrap(); + } } }