test input cases satisfied (wont' built)

This commit is contained in:
Henry Schimke
2022-08-23 13:44:14 -05:00
parent 63410c4615
commit a47796c3b8
2 changed files with 21 additions and 18 deletions

View File

@@ -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));
}
}

View File

@@ -157,7 +157,7 @@ impl GenericGF {
/**
* @return the monomial representing coefficient * x^degree
*/
pub fn buildMonomial(&self, degree: usize, coefficient: usize) -> Box<GenericGFPoly> {
pub fn buildMonomial(&self, degree: usize, coefficient: i32) -> Box<GenericGFPoly> {
if (coefficient == 0) {
return self.zero;
}
@@ -258,7 +258,7 @@ impl fmt::Display for GenericGF {
#[derive(Debug)]
pub struct GenericGFPoly {
field: Box<GenericGF>,
coefficients: Vec<usize>,
coefficients: Vec<i32>,
}
impl PartialEq for GenericGFPoly {
@@ -280,7 +280,7 @@ impl GenericGFPoly {
*/
pub fn new(
field: Box<GenericGF>,
coefficients: &Vec<usize>,
coefficients: &Vec<i32>,
) -> Result<Self, IllegalArgumentException> {
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<Box<GenericGFPoly>, IllegalArgumentException> {
if (degree < 0) {
return Err(IllegalArgumentException::new(""));