From a47796c3b86a3299a508822a6051efa2931cf9ec Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Tue, 23 Aug 2022 13:44:14 -0500 Subject: [PATCH] test input cases satisfied (wont' built) --- .../reedsolomon/GenericGFPolyTestCase.rs | 31 ++++++++++--------- src/common/reedsolomon/mod.rs | 8 ++--- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/common/reedsolomon/GenericGFPolyTestCase.rs b/src/common/reedsolomon/GenericGFPolyTestCase.rs index 37aefff..d611989 100644 --- a/src/common/reedsolomon/GenericGFPolyTestCase.rs +++ b/src/common/reedsolomon/GenericGFPolyTestCase.rs @@ -25,25 +25,28 @@ use super::{GenericGF, GenericGFPoly}; * Tests {@link GenericGFPoly}. */ - const FIELD :GenericGF= super::QR_CODE_FIELD_256; +const FIELD: GenericGF = super::QR_CODE_FIELD_256; - #[test] - fn testPolynomialString() { +#[test] +fn testPolynomialString() { assert_eq!("0", FIELD.getZero().to_string()); assert_eq!("-1", FIELD.buildMonomial(0, -1).to_string()); - let p = GenericGFPoly::new(Box::new(FIELD), &vec![3, 0, -2, 1, 1]).unwrap(); + let p = GenericGFPoly::new(Box::new(FIELD), &vec![3, 0, -2, 1, 1]).unwrap(); assert_eq!("a^25x^4 - ax^2 + x + 1", p.to_string()); - let p = GenericGFPoly::new(Box::new(FIELD), &vec![3]).unwrap(); + let p = GenericGFPoly::new(Box::new(FIELD), &vec![3]).unwrap(); assert_eq!("a^25", p.to_string()); - } +} - #[test] - fn testZero() { - assert_eq!(*FIELD.getZero(),*FIELD.buildMonomial(1, 0)); - assert_eq!(*FIELD.getZero(), *FIELD.buildMonomial(1, 2).multiply(0).unwrap()); - } +#[test] +fn testZero() { + assert_eq!(*FIELD.getZero(), *FIELD.buildMonomial(1, 0)); + assert_eq!( + *FIELD.getZero(), + *FIELD.buildMonomial(1, 2).multiply_with_scalar(0) + ); +} - #[test] - fn testEvaluate() { +#[test] +fn testEvaluate() { assert_eq!(3, FIELD.buildMonomial(0, 3).evaluateAt(0)); - } \ No newline at end of file +} diff --git a/src/common/reedsolomon/mod.rs b/src/common/reedsolomon/mod.rs index 0e039bc..f5e7470 100644 --- a/src/common/reedsolomon/mod.rs +++ b/src/common/reedsolomon/mod.rs @@ -157,7 +157,7 @@ impl GenericGF { /** * @return the monomial representing coefficient * x^degree */ - pub fn buildMonomial(&self, degree: usize, coefficient: usize) -> Box { + pub fn buildMonomial(&self, degree: usize, coefficient: i32) -> Box { if (coefficient == 0) { return self.zero; } @@ -258,7 +258,7 @@ impl fmt::Display for GenericGF { #[derive(Debug)] pub struct GenericGFPoly { field: Box, - coefficients: Vec, + coefficients: Vec, } impl PartialEq for GenericGFPoly { @@ -280,7 +280,7 @@ impl GenericGFPoly { */ pub fn new( field: Box, - coefficients: &Vec, + coefficients: &Vec, ) -> Result { if (coefficients.len() == 0) { return Err(IllegalArgumentException::new("")); @@ -472,7 +472,7 @@ impl GenericGFPoly { pub fn multiplyByMonomial( &self, degree: usize, - coefficient: usize, + coefficient: i32, ) -> Result, IllegalArgumentException> { if (degree < 0) { return Err(IllegalArgumentException::new(""));