ArrayDecoders { public static int[] runlengthDecode(int[] integerArray) { int totCount =0; for(int i=0; i<integerArray.length;i+=2){ totCount+=integerArray[i+1]; } int[] outArray = new int[totCount]; int index = 0; for (int i=0; i<integerArray.length; i+=2) { int currentInt = integerArray[i]; int currentCount = integerArray[i+1]; for (int j=0; j<currentCount;j++){ outArray[index] = currentInt; index++; } } return outArray; }  static int[] deltaDecode(int[] intArray); static int[] runlengthDecode(int[] integerArray);  }
@Test public final void runLengthDecodeTest() { int[] inputData = {15,3,100,2,111,4,10000,6}; int[] outputDataTest = {15,15,15,100,100,111,111,111,111,10000,10000,10000,10000,10000,10000}; int[] outputData = ArrayDecoders.runlengthDecode(inputData); assertArrayEquals(outputDataTest, outputData); }
@Test public final void emptyRunLengthDecodeTest() { int[] inputData = {}; int[] outputDataTest = {}; int[] outputData = ArrayDecoders.runlengthDecode(inputData); assertArrayEquals(outputDataTest, outputData); }