protected void doRandomRoundTripTest(final IRabaCoder dataCoder,final int size,final int capacity) throws IOException {
  assert capacity >= size;
  if (dataCoder.isValueCoder()) {
    final byte[][] data=new byte[capacity][];
    for (int i=0; i < size; i++) {
      final boolean isNull=r.nextFloat() < .03;
      if (isNull) {
        data[i]=null;
      }
 else {
        data[i]=getRandomValue(dataCoder);
      }
    }
    final IRaba raba=new ReadOnlyValuesRaba(0,size,capacity,data);
    doRoundTripTest(dataCoder,raba);
  }
  if (dataCoder.isKeyCoder()) {
    final byte[][] data=new byte[capacity][];
    final int nominalIncRange=5000;
    long lastKey=r.nextLong();
    int nactual=0;
    for (int i=0; i < size; i++, nactual++) {
      data[i]=TestKeyBuilder.asSortKey(lastKey);
      final long remainder=Long.MAX_VALUE - lastKey;
      if (remainder == 1) {
        break;
      }
      final int incRange=(int)Math.max(nominalIncRange,Math.min(nominalIncRange,remainder));
      final int inc=r.nextInt(incRange) + 1;
      lastKey+=inc;
    }
    final IRaba raba=new ReadOnlyKeysRaba(0,nactual,capacity,data);
    doRoundTripTest(dataCoder,raba);
  }
}

protected void doRandomRoundTripTest ( final IRabaCoder dataCoder , final int size , final int capacity ) throws IOException { assert capacity >= size ; if ( dataCoder . isValueCoder ( ) ) { final byte [ ] [ ] data = new byte [ capacity ] [ ] ; for ( int i = 0 ; i < size ; i ++ ) { final boolean isNull = r . nextFloat ( ) < .03 ; if ( isNull ) { data [ i ] = null ; } else { data [ i ] = getRandomValue ( dataCoder ) ; } } final IRaba raba = new ReadOnlyValuesRaba ( 0 , size , capacity , data ) ; doRoundTripTest ( dataCoder , raba ) ; } if ( dataCoder . isKeyCoder ( ) ) { final byte [ ] [ ] data = new byte [ capacity ] [ ] ; final int nominalIncRange = 5000 ; long lastKey = r . nextLong ( ) ; int nactual = 0 ; for ( int i = 0 ; i < size ; i ++ , nactual ++ ) { data [ i ] = TestKeyBuilder . asSortKey ( lastKey ) ; final long remainder = Long . MAX_VALUE - lastKey ; if ( remainder == 1 ) { break ; } final int incRange = ( int ) Math . max ( nominalIncRange , Math . min ( nominalIncRange , remainder ) ) ; final int inc = r . nextInt ( incRange ) + 1 ; lastKey += inc ; } final IRaba raba = new ReadOnlyKeysRaba ( 0 , nactual , capacity , data ) ; doRoundTripTest ( dataCoder , raba ) ; } }
generates a random byte [ ] [ ] and verifies round - trip encoding and decoding . < p > note : this uses a uniform random distribution . therefore the huffman codes tend to occupy more space than the original byte [ ] [ ] since the canonical huffman code can not be shorter than the original byte values on average when all values are equally likely . when you want to measure the expected compression ratio you need to test with a gaussian distribution ( bell curve ) over the values , a usascii distribution , etc .
