Skip to content

Commit

Permalink
adds polynomials tests
Browse files Browse the repository at this point in the history
  • Loading branch information
supinie committed Apr 15, 2024
1 parent 58f5d8c commit f98c1c5
Showing 1 changed file with 94 additions and 4 deletions.
98 changes: 94 additions & 4 deletions src/tests/polynomials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value = [i16; N]> {
pub(in crate::tests) fn new_limited_poly_array() -> impl Strategy<Value = [i16; N]> {
prop::array::uniform(-(Q as i16)..(Q as i16))
}

pub(in crate::tests) fn new_poly_array() -> impl Strategy<Value = [i16; N]> {
prop::array::uniform(i16::MIN..i16::MAX)
}

#[test]
fn new_test() {
let poly = Poly::new();
Expand All @@ -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]
Expand All @@ -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();
}
}
}

0 comments on commit f98c1c5

Please sign in to comment.