String of zero polynomial be "0" (#1020)

* String of zero polynomial be "0"

* add test

* add more test

* modify test case
This commit is contained in:
MakKi (makki_d) 2018-06-03 12:32:30 +09:00 committed by Sean Owen
parent 4d39673d67
commit 3778715156
2 changed files with 11 additions and 1 deletions

View file

@ -225,6 +225,9 @@ final class GenericGFPoly {
@Override
public String toString() {
if (isZero()) {
return "0";
}
StringBuilder result = new StringBuilder(8 * getDegree());
for (int degree = getDegree(); degree >= 0; degree--) {
int coefficient = getCoefficient(degree);

View file

@ -393,6 +393,13 @@ public final class ReedSolomonTestCase extends Assert {
testEncodeDecodeRandom(GenericGF.AZTEC_DATA_12, 3072, 1023);
}
@Test
public void testPolynomialString() {
assertEquals("0", GenericGF.QR_CODE_FIELD_256.getZero().toString());
GenericGFPoly p = new GenericGFPoly(GenericGF.QR_CODE_FIELD_256, new int[] {3, 0, -2, 1, 1});
assertEquals("a^25x^4 - ax^2 + x + 1", p.toString());
}
public static void corrupt(int[] received, int howMany, Random random, int max) {
BitSet corrupted = new BitSet(received.length);
for (int j = 0; j < howMany; j++) {
@ -503,4 +510,4 @@ public final class ReedSolomonTestCase extends Assert {
return new Random(0xDEADBEEF);
}
}
}