feat: ready test runner for monic and sqrt tasks
This commit is contained in:
parent
f75e7de733
commit
5bb9bcebff
4 changed files with 53 additions and 30 deletions
|
|
@ -81,21 +81,21 @@ impl Polynomial {
|
|||
//eprintln!("Current exponent: {:02X}", exponent);
|
||||
if exponent & 1 == 1 {
|
||||
let temp = &self * &result;
|
||||
eprintln!("Mult");
|
||||
eprintln!("After mod: {:?}", temp);
|
||||
//eprintln!("Mult");
|
||||
//eprintln!("After mod: {:?}", temp);
|
||||
|
||||
result = temp
|
||||
}
|
||||
let temp_square = &self * &self;
|
||||
eprintln!("Square");
|
||||
//eprintln!("Square");
|
||||
|
||||
eprintln!("After squaring: {:?}", temp_square);
|
||||
//eprintln!("After squaring: {:?}", temp_square);
|
||||
self = temp_square;
|
||||
//eprintln!("After mod: {:?}", self);
|
||||
exponent >>= 1;
|
||||
}
|
||||
|
||||
eprintln!("result in powmod before reduction: {:02X?}", result);
|
||||
//eprintln!("result in powmod before reduction: {:02X?}", result);
|
||||
|
||||
while !result.polynomial.is_empty()
|
||||
&& result
|
||||
|
|
@ -109,7 +109,7 @@ impl Polynomial {
|
|||
result.polynomial.pop();
|
||||
}
|
||||
|
||||
eprintln!("result in powmod after reduction: {:02X?}", result);
|
||||
//eprintln!("result in powmod after reduction: {:02X?}", result);
|
||||
|
||||
if result.is_empty() {
|
||||
result = Polynomial::new(vec![FieldElement::new(vec![0; 16])]);
|
||||
|
|
@ -256,7 +256,7 @@ impl Polynomial {
|
|||
true
|
||||
}
|
||||
|
||||
fn monic(mut self) -> Self {
|
||||
pub fn monic(&mut self) {
|
||||
let divident = self.polynomial.last().unwrap().clone();
|
||||
|
||||
for fieldelement in &mut self.polynomial.iter_mut() {
|
||||
|
|
@ -274,15 +274,9 @@ impl Polynomial {
|
|||
{
|
||||
self.polynomial.pop();
|
||||
}
|
||||
|
||||
if self.is_empty() {
|
||||
self = Polynomial::new(vec![FieldElement::new(vec![0; 16])]);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
fn sqrt(self) -> Self {
|
||||
pub fn sqrt(self) -> Self {
|
||||
let mut result = vec![];
|
||||
|
||||
for (position, element) in self.polynomial.iter().enumerate() {
|
||||
|
|
@ -1135,22 +1129,22 @@ mod tests {
|
|||
"1Ial5rAJGOucIdUe3zh5bw==",
|
||||
"gAAAAAAAAAAAAAAAAAAAAA=="
|
||||
]);
|
||||
let element1: Polynomial = Polynomial::from_c_array(&json1);
|
||||
let mut element1: Polynomial = Polynomial::from_c_array(&json1);
|
||||
|
||||
let result = element1.monic();
|
||||
element1.monic();
|
||||
|
||||
assert_eq!(json!(result.to_c_array()), expected);
|
||||
assert_eq!(json!(element1.to_c_array()), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_poly_monic_poly_zero() {
|
||||
let json1 = json!(["AAAAAAAAAAAAAAAAAAAAAA=="]);
|
||||
let expected = json!(["AAAAAAAAAAAAAAAAAAAAAA=="]);
|
||||
let element1: Polynomial = Polynomial::from_c_array(&json1);
|
||||
let mut element1: Polynomial = Polynomial::from_c_array(&json1);
|
||||
|
||||
let result = element1.monic();
|
||||
element1.monic();
|
||||
|
||||
assert_eq!(json!(result.to_c_array()), expected);
|
||||
assert_eq!(json!(element1.to_c_array()), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -1162,11 +1156,11 @@ mod tests {
|
|||
"AAAAAAAAAAAAAAAAAAAAAA=="
|
||||
]);
|
||||
let expected = json!(["AAAAAAAAAAAAAAAAAAAAAA=="]);
|
||||
let element1: Polynomial = Polynomial::from_c_array(&json1);
|
||||
let mut element1: Polynomial = Polynomial::from_c_array(&json1);
|
||||
|
||||
let result = element1.monic();
|
||||
element1.monic();
|
||||
|
||||
assert_eq!(json!(result.to_c_array()), expected);
|
||||
assert_eq!(json!(element1.to_c_array()), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue