public void testQuantization() throws Exception {
  Random random=random();
  for (int i=0; i < 10000; i++) {
    int encoded=random.nextInt();
    if (encoded < Geo3DUtil.MIN_ENCODED_VALUE) {
      continue;
    }
    if (encoded > Geo3DUtil.MAX_ENCODED_VALUE) {
      continue;
    }
    double min=encoded * Geo3DUtil.DECODE;
    double decoded=Geo3DUtil.decodeValueFloor(encoded);
    assertEquals(min,decoded,0.0D);
    assertEquals(encoded,Geo3DUtil.encodeValue(decoded));
    if (encoded != Integer.MAX_VALUE) {
      double max=min + Geo3DUtil.DECODE;
      assertEquals(max,Geo3DUtil.decodeValueFloor(encoded + 1),0.0D);
      assertEquals(encoded + 1,Geo3DUtil.encodeValue(max));
      double minEdge=Math.nextUp(min);
      double maxEdge=Math.nextDown(max);
      assertEquals(encoded,Geo3DUtil.encodeValue(minEdge));
      assertEquals(encoded,Geo3DUtil.encodeValue(maxEdge));
      long minBits=NumericUtils.doubleToSortableLong(minEdge);
      long maxBits=NumericUtils.doubleToSortableLong(maxEdge);
      for (int j=0; j < 100; j++) {
        double value=NumericUtils.sortableLongToDouble(TestUtil.nextLong(random,minBits,maxBits));
        assertEquals(encoded,Geo3DUtil.encodeValue(value));
      }
    }
  }
}

public void testQuantization ( ) throws Exception { Random random = random ( ) ; for ( int i = 0 ; i < 10000 ; i ++ ) { int encoded = random . nextInt ( ) ; if ( encoded < Geo3DUtil . MIN_ENCODED_VALUE ) { continue ; } if ( encoded > Geo3DUtil . MAX_ENCODED_VALUE ) { continue ; } double min = encoded * Geo3DUtil . DECODE ; double decoded = Geo3DUtil . decodeValueFloor ( encoded ) ; assertEquals ( min , decoded , 0.0D ) ; assertEquals ( encoded , Geo3DUtil . encodeValue ( decoded ) ) ; if ( encoded != Integer . MAX_VALUE ) { double max = min + Geo3DUtil . DECODE ; assertEquals ( max , Geo3DUtil . decodeValueFloor ( encoded + 1 ) , 0.0D ) ; assertEquals ( encoded + 1 , Geo3DUtil . encodeValue ( max ) ) ; double minEdge = Math . nextUp ( min ) ; double maxEdge = Math . nextDown ( max ) ; assertEquals ( encoded , Geo3DUtil . encodeValue ( minEdge ) ) ; assertEquals ( encoded , Geo3DUtil . encodeValue ( maxEdge ) ) ; long minBits = NumericUtils . doubleToSortableLong ( minEdge ) ; long maxBits = NumericUtils . doubleToSortableLong ( maxEdge ) ; for ( int j = 0 ; j < 100 ; j ++ ) { double value = NumericUtils . sortableLongToDouble ( TestUtil . nextLong ( random , minBits , maxBits ) ) ; assertEquals ( encoded , Geo3DUtil . encodeValue ( value ) ) ; } } } }
step through some integers , ensuring they decode to their expected double values . double values start at - planetmax and increase by geo3dutil . decode for each integer . check edge cases within the double range and random doubles within the range too .
