diff --git a/common/src/test/java/com/cldellow/manu/common/IntVectorTest.java b/common/src/test/java/com/cldellow/manu/common/IntVectorTest.java index bc3494c..e19e298 100644 --- a/common/src/test/java/com/cldellow/manu/common/IntVectorTest.java +++ b/common/src/test/java/com/cldellow/manu/common/IntVectorTest.java @@ -62,8 +62,8 @@ public void testVectorSetOOBE() { } @Property - public void testLikeArray(int[] ints) { - IntVector iv = new IntVector(); + public void testLikeArray(int[] ints, boolean grow) { + IntVector iv = grow ? new IntVector(1) : new IntVector(); for (int i = 0; i < ints.length; i++) { assertEquals(i, iv.getSize()); iv.add(ints[i]); diff --git a/format/src/test/java/com/cldellow/manu/format/LengthOpsTest.java b/format/src/test/java/com/cldellow/manu/format/LengthOpsTest.java index da168be..70c8c55 100644 --- a/format/src/test/java/com/cldellow/manu/format/LengthOpsTest.java +++ b/format/src/test/java/com/cldellow/manu/format/LengthOpsTest.java @@ -53,7 +53,15 @@ public void encodeTooSmallLen(@InRange(max = "-1") int len) { @Property - public void decodeIdAnyLen(@InRange(min = "0", max = "63") int id, @InRange(min = "0") int len) { + public void decodeIdAnyLen(@InRange(min = "0", max = "63") int id, @InRange(min = "0", max = "254") int smallLen, @InRange(min = "255", max = "65534") int mediumLen, @InRange(min = "65535") int largeLen, @InRange(min = "0", max = "2") int lenSelect) { + int len; + + switch (lenSelect) { + case 2: len = largeLen; break; + case 1: len = mediumLen; break; + case 0: len = smallLen; break; + default: throw new Error("Dead code"); + } byte encoded = LengthOps.encode((byte) id, len); assertEquals(id, LengthOps.decodeId(encoded)); diff --git a/format/src/test/java/com/cldellow/manu/format/ReaderTest.java b/format/src/test/java/com/cldellow/manu/format/ReaderTest.java index 982d9f0..990f9ad 100644 --- a/format/src/test/java/com/cldellow/manu/format/ReaderTest.java +++ b/format/src/test/java/com/cldellow/manu/format/ReaderTest.java @@ -2,8 +2,10 @@ import com.cldellow.manu.common.Common; import com.pholser.junit.quickcheck.Property; +import com.pholser.junit.quickcheck.generator.InRange; import com.pholser.junit.quickcheck.generator.Size; import com.pholser.junit.quickcheck.runner.JUnitQuickcheck; +import junit.framework.AssertionFailedError; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; @@ -143,14 +145,47 @@ public void testSparseRecordsIterator() throws Exception { } } + private void testVariableSizes(int[] f1, int[] f2, int[] f3, int[] f4, int encoder) throws Exception { + FieldEncoder e; + switch (encoder) { + case 0: + e = new CopyEncoder(); + break; + case 1: + e = new PFOREncoder(); + break; + case 2: + e = new SingleValueEncoder(); + f1 = new int[] { f1[0] }; + f2 = new int[] { f2[0] }; + f3 = new int[] { f3[0] }; + f4 = new int[] { f4[0] }; + break; + case 3: + e = new AverageEncoder(); + for (int i = 1 ; i < f1.length ; i++) { + f1[i] = f1[0]; + f2[i] = f2[0]; + f3[i] = f3[0]; + f4[i] = f4[0]; + } + break; + default: + throw new Error(); + } + + testVariableSize(f1, f2, f3, f4, e); + } + @Property(trials = 5) public void testVariableSize512( int @Size(min = 512, max = 512) [] f1, int @Size(min = 512, max = 512) [] f2, int @Size(min = 512, max = 512) [] f3, - int @Size(min = 512, max = 512) [] f4 + int @Size(min = 512, max = 512) [] f4, + @InRange(min="0", max="3") int encoder ) throws Exception { - testVariableSize(f1, f2, f3, f4); + testVariableSizes(f1, f2, f3, f4, encoder); } @Property(trials = 5) @@ -158,9 +193,10 @@ public void testVariableSize20K( int @Size(min = 20480, max = 20480) [] f1, int @Size(min = 20480, max = 20480) [] f2, int @Size(min = 20480, max = 20480) [] f3, - int @Size(min = 20480, max = 20480) [] f4 + int @Size(min = 20480, max = 20480) [] f4, + @InRange(min="0", max="2") int encoder ) throws Exception { - testVariableSize(f1, f2, f3, f4); + testVariableSizes(f1, f2, f3, f4, encoder); } @Test @@ -188,6 +224,11 @@ void testVariableSize(int[] f1, int[] f2, int[] f3, int[] f4) throws Exception { FieldEncoder encoder = new CopyEncoder(); if (f1.length == 1) encoder = new AverageEncoder(); + + testVariableSize(f1, f2, f3, f4, encoder); + } + + void testVariableSize(int[] f1, int[] f2, int[] f3, int[] f4, FieldEncoder encoder) throws Exception { int[][] values1 = new int[][]{f1, f2}; SimpleRecord r1 = new SimpleRecord(1, new FieldEncoder[]{encoder, encoder}, values1);