Program: 112958
Project: 112958
Buggy source:
@Test public void testPredefinedSpatialEntries() throws Exception {
  final NumericIndexStrategy strategy=new SpatialDimensionalityTypeProvider().createPrimaryIndex().getIndexStrategy();
  for (int sfcIndex=0; sfcIndex < DEFINED_BITS_OF_PRECISION.length; sfcIndex++) {
    final NumericData[] dataPerDimension=new NumericData[2];
    final double precision=360 / Math.pow(2,DEFINED_BITS_OF_PRECISION[sfcIndex]);
    if (precision > 180) {
      dataPerDimension[0]=new NumericRange(-180,180);
      dataPerDimension[1]=new NumericRange(-90,90);
    }
 else {
      dataPerDimension[0]=new NumericRange(0,precision);
      dataPerDimension[1]=new NumericRange(-precision,0);
    }
    final MultiDimensionalNumericData indexedData=new BasicNumericDataset(dataPerDimension);
    final List<ByteArrayId> ids=strategy.getInsertionIds(indexedData);
    final NumericData[] queryRangePerDimension=new NumericData[2];
    queryRangePerDimension[0]=new NumericRange(dataPerDimension[0].getMin() + QUERY_RANGE_EPSILON,dataPerDimension[0].getMax() - QUERY_RANGE_EPSILON);
    queryRangePerDimension[1]=new NumericRange(dataPerDimension[1].getMin() + QUERY_RANGE_EPSILON,dataPerDimension[1].getMax() - QUERY_RANGE_EPSILON);
    final MultiDimensionalNumericData queryData=new BasicNumericDataset(queryRangePerDimension);
    final List<ByteArrayRange> queryRanges=strategy.getQueryRanges(queryData);
    final Set<Byte> queryRangeTiers=new HashSet<Byte>();
    boolean rangeAtTierFound=false;
    for (    final ByteArrayRange range : queryRanges) {
      final byte tier=range.getStart().getBytes()[0];
      queryRangeTiers.add(range.getStart().getBytes()[0]);
      if (tier == DEFINED_BITS_OF_PRECISION[sfcIndex]) {
        if (rangeAtTierFound) {
          throw new Exception("String_Node_Str" + tier);
        }
        assertEquals("String_Node_Str" + DEFINED_BITS_OF_PRECISION[sfcIndex],range.getStart(),range.getEnd());
        rangeAtTierFound=true;
      }
    }
    if (!rangeAtTierFound) {
      throw new Exception("String_Node_Str" + DEFINED_BITS_OF_PRECISION[sfcIndex]);
    }
    if ((ids.get(0).getBytes()[0] == 0) || ((sfcIndex == (DEFINED_BITS_OF_PRECISION.length - 1)) || (DEFINED_BITS_OF_PRECISION[sfcIndex + 1] != (DEFINED_BITS_OF_PRECISION[sfcIndex] + 1)))) {
      assertEquals("String_Node_Str" + DEFINED_BITS_OF_PRECISION[sfcIndex],DEFINED_BITS_OF_PRECISION[sfcIndex],ids.get(0).getBytes()[0]);
      assertEquals("String_Node_Str" + DEFINED_BITS_OF_PRECISION[sfcIndex],1,ids.size());
    }
 else {
      assertEquals("String_Node_Str" + DEFINED_BITS_OF_PRECISION[sfcIndex + 1],DEFINED_BITS_OF_PRECISION[sfcIndex + 1],ids.get(0).getBytes()[0]);
      final int expectedIds=(precision > 90) && (precision <= 180) ? 2 : 4;
      assertEquals("String_Node_Str" + expectedIds + "String_Node_Str"+ DEFINED_BITS_OF_PRECISION[sfcIndex + 1],expectedIds,ids.size());
    }
  }
}

Fixed version (ground truth):
@Test public void testPredefinedSpatialEntries() throws Exception {
  final NumericIndexStrategy strategy=TieredSFCIndexFactory.createDefinedPrecisionTieredStrategy(new NumericDimensionDefinition[]{new LongitudeDefinition(),new LatitudeDefinition(true)},new int[][]{DEFINED_BITS_OF_PRECISION.clone(),DEFINED_BITS_OF_PRECISION.clone()},SFCType.HILBERT);
  for (int sfcIndex=0; sfcIndex < DEFINED_BITS_OF_PRECISION.length; sfcIndex++) {
    final NumericData[] dataPerDimension=new NumericData[2];
    final double precision=360 / Math.pow(2,DEFINED_BITS_OF_PRECISION[sfcIndex]);
    if (precision > 180) {
      dataPerDimension[0]=new NumericRange(-180,180);
      dataPerDimension[1]=new NumericRange(-90,90);
    }
 else {
      dataPerDimension[0]=new NumericRange(0,precision);
      dataPerDimension[1]=new NumericRange(-precision,0);
    }
    final MultiDimensionalNumericData indexedData=new BasicNumericDataset(dataPerDimension);
    final List<ByteArrayId> ids=strategy.getInsertionIds(indexedData);
    final NumericData[] queryRangePerDimension=new NumericData[2];
    queryRangePerDimension[0]=new NumericRange(dataPerDimension[0].getMin() + QUERY_RANGE_EPSILON,dataPerDimension[0].getMax() - QUERY_RANGE_EPSILON);
    queryRangePerDimension[1]=new NumericRange(dataPerDimension[1].getMin() + QUERY_RANGE_EPSILON,dataPerDimension[1].getMax() - QUERY_RANGE_EPSILON);
    final MultiDimensionalNumericData queryData=new BasicNumericDataset(queryRangePerDimension);
    final List<ByteArrayRange> queryRanges=strategy.getQueryRanges(queryData);
    final Set<Byte> queryRangeTiers=new HashSet<Byte>();
    boolean rangeAtTierFound=false;
    for (    final ByteArrayRange range : queryRanges) {
      final byte tier=range.getStart().getBytes()[0];
      queryRangeTiers.add(range.getStart().getBytes()[0]);
      if (tier == DEFINED_BITS_OF_PRECISION[sfcIndex]) {
        if (rangeAtTierFound) {
          throw new Exception("String_Node_Str" + tier);
        }
        assertEquals("String_Node_Str" + DEFINED_BITS_OF_PRECISION[sfcIndex],range.getStart(),range.getEnd());
        rangeAtTierFound=true;
      }
    }
    if (!rangeAtTierFound) {
      throw new Exception("String_Node_Str" + DEFINED_BITS_OF_PRECISION[sfcIndex]);
    }
    if ((ids.get(0).getBytes()[0] == 0) || ((sfcIndex == (DEFINED_BITS_OF_PRECISION.length - 1)) || (DEFINED_BITS_OF_PRECISION[sfcIndex + 1] != (DEFINED_BITS_OF_PRECISION[sfcIndex] + 1)))) {
      assertEquals("String_Node_Str" + DEFINED_BITS_OF_PRECISION[sfcIndex],DEFINED_BITS_OF_PRECISION[sfcIndex],ids.get(0).getBytes()[0]);
      assertEquals("String_Node_Str" + DEFINED_BITS_OF_PRECISION[sfcIndex],1,ids.size());
    }
 else {
      assertEquals("String_Node_Str" + DEFINED_BITS_OF_PRECISION[sfcIndex + 1],DEFINED_BITS_OF_PRECISION[sfcIndex + 1],ids.get(0).getBytes()[0]);
      final int expectedIds=(precision > 90) && (precision <= 180) ? 2 : 4;
      assertEquals("String_Node_Str" + expectedIds + "String_Node_Str"+ DEFINED_BITS_OF_PRECISION[sfcIndex + 1],expectedIds,ids.size());
    }
  }
}