Program: 4540
Project: 4540
Buggy source:
/** 
 * Test the input description generation, top-down compute, and bucket support on a periodic encoder
 */
@Test public void testDecodeAndResolution(){
  setUp();
  parameters.setName("String_Node_Str");
  initSE();
  double resolution=mem.getResolution();
  System.out.println("String_Node_Str" + resolution);
  StringBuilder out=new StringBuilder();
  for (double v=mem.getMinVal(); v < mem.getMaxVal(); v+=(resolution / 4.0d)) {
    int[] output=se.encode(mem,v);
    Decode decoded=se.decode(mem,output,"String_Node_Str");
    System.out.println(out.append("String_Node_Str").append(Arrays.toString(output)).append("String_Node_Str").append(String.format("String_Node_Str",v)).append("String_Node_Str").append(se.decodedToStr(decoded)));
    out.setLength(0);
    Map<String,Ranges> fieldsMap=decoded.getFields();
    assertEquals(1,fieldsMap.size());
    Ranges ranges=(Ranges)new ArrayList<Ranges>(fieldsMap.values()).get(0);
    assertEquals(1,ranges.size());
    assertEquals(ranges.getRange(0).min(),ranges.getRange(0).max(),0);
    assertTrue(ranges.getRange(0).min() - v < mem.getResolution());
    EncoderResult topDown=se.topDownCompute(mem,output);
    System.out.println("String_Node_Str" + topDown);
    assertTrue(topDown.get(3).equals(Arrays.toString(output)));
    assertTrue(Math.abs(((double)topDown.get(1)) - v) <= mem.getResolution() / 2);
    int[] bucketIndices=se.getBucketIndices(mem,v);
    System.out.println("String_Node_Str" + bucketIndices[0]);
    topDown=se.getBucketInfo(mem,bucketIndices);
    assertTrue(Math.abs(((double)topDown.get(1)) - v) <= mem.getResolution() / 2);
    assertEquals(topDown.get(1),se.getBucketValues(mem).toArray()[bucketIndices[0]]);
    assertEquals(topDown.get(2),topDown.get(1));
    assertTrue(topDown.get(3).equals(Arrays.toString(output)));
  }
  setUp();
  parameters.setName("String_Node_Str");
  parameters.setRadius(1.5);
  parameters.setW(3);
  parameters.setMinVal(1);
  parameters.setMaxVal(8);
  parameters.setPeriodic(true);
  parameters.setForced(true);
  initSE();
  System.out.println("String_Node_Str" + mem.getResolution());
  int[] encoded=new int[]{1,0,0,0,0,0,0,0,0,0,0,0,1,0};
  Decode decoded=se.decode(mem,encoded,"String_Node_Str");
  Map<String,Ranges> fieldsMap=decoded.getFields();
  assertEquals(1,fieldsMap.size());
  assertEquals(1,decoded.getRanges("String_Node_Str").size());
  assertEquals(decoded.getRanges("String_Node_Str").getRange(0).toString(),"String_Node_Str");
  encoded=new int[]{1,1,0,0,0,0,0,0,0,0,0,0,1,0};
  decoded=se.decode(mem,encoded,"String_Node_Str");
  fieldsMap=decoded.getFields();
  assertEquals(1,fieldsMap.size());
  assertEquals(2,decoded.getRanges("String_Node_Str").size());
  assertEquals(decoded.getRanges("String_Node_Str").getRange(0).toString(),"String_Node_Str");
  encoded=new int[]{1,1,1,1,1,0,0,0,0,0,0,0,0,0};
  decoded=se.decode(mem,encoded,"String_Node_Str");
  fieldsMap=decoded.getFields();
  assertEquals(1,fieldsMap.size());
  assertEquals(1,decoded.getRanges("String_Node_Str").size());
  assertEquals(decoded.getRanges("String_Node_Str").getRange(0).toString(),"String_Node_Str");
  encoded=new int[]{1,1,1,0,0,0,0,0,1,1,1,1,0,0};
  decoded=se.decode(mem,encoded,"String_Node_Str");
  fieldsMap=decoded.getFields();
  assertEquals(1,fieldsMap.size());
  assertEquals(2,decoded.getRanges("String_Node_Str").size());
  assertEquals(decoded.getRanges("String_Node_Str").getRange(0).toString(),"String_Node_Str");
  assertEquals(decoded.getRanges("String_Node_Str").getRange(1).toString(),"String_Node_Str");
  encoded=new int[]{0,1,0,0,0,0,0,0,1,1,1,1,0,0};
  decoded=se.decode(mem,encoded,"String_Node_Str");
  fieldsMap=decoded.getFields();
  assertEquals(1,fieldsMap.size());
  assertEquals(2,decoded.getRanges("String_Node_Str").size());
  assertEquals(decoded.getRanges("String_Node_Str").getRange(0).toString(),"String_Node_Str");
  assertEquals(decoded.getRanges("String_Node_Str").getRange(1).toString(),"String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Test the input description generation, top-down compute, and bucket support on a periodic encoder
 */
@Test public void testDecodeAndResolution(){
  setUp();
  parameters.setName("String_Node_Str");
  initSE();
  double resolution=mem.getResolution();
  System.out.println("String_Node_Str" + resolution);
  StringBuilder out=new StringBuilder();
  for (double v=mem.getMinVal(); v < mem.getMaxVal(); v+=(resolution / 4.0d)) {
    int[] output=se.encode(mem,v);
    Decode decoded=se.decode(mem,output,"String_Node_Str");
    System.out.println(out.append("String_Node_Str").append(Arrays.toString(output)).append("String_Node_Str").append(String.format("String_Node_Str",v)).append("String_Node_Str").append(se.decodedToStr(decoded)));
    out.setLength(0);
    Map<String,Ranges> fieldsMap=decoded.getFields();
    assertEquals(1,fieldsMap.size());
    Ranges ranges=(Ranges)new ArrayList<Ranges>(fieldsMap.values()).get(0);
    assertEquals(1,ranges.size());
    assertEquals(ranges.getRange(0).min(),ranges.getRange(0).max(),0);
    assertTrue(ranges.getRange(0).min() - v < mem.getResolution());
    EncoderResult topDown=se.topDownCompute(mem,output);
    System.out.println("String_Node_Str" + topDown);
    assertTrue(topDown.get(3).equals(Arrays.toString(output)));
    assertTrue(Math.abs(((Double)topDown.get(1)) - v) <= mem.getResolution() / 2);
    int[] bucketIndices=se.getBucketIndices(mem,v);
    System.out.println("String_Node_Str" + bucketIndices[0]);
    topDown=se.getBucketInfo(mem,bucketIndices);
    assertTrue(Math.abs(((Double)topDown.get(1)) - v) <= mem.getResolution() / 2);
    assertEquals(topDown.get(1),se.getBucketValues(mem).toArray()[bucketIndices[0]]);
    assertEquals(topDown.get(2),topDown.get(1));
    assertTrue(topDown.get(3).equals(Arrays.toString(output)));
  }
  setUp();
  parameters.setName("String_Node_Str");
  parameters.setRadius(1.5);
  parameters.setW(3);
  parameters.setMinVal(1);
  parameters.setMaxVal(8);
  parameters.setPeriodic(true);
  parameters.setForced(true);
  initSE();
  System.out.println("String_Node_Str" + mem.getResolution());
  int[] encoded=new int[]{1,0,0,0,0,0,0,0,0,0,0,0,1,0};
  Decode decoded=se.decode(mem,encoded,"String_Node_Str");
  Map<String,Ranges> fieldsMap=decoded.getFields();
  assertEquals(1,fieldsMap.size());
  assertEquals(1,decoded.getRanges("String_Node_Str").size());
  assertEquals(decoded.getRanges("String_Node_Str").getRange(0).toString(),"String_Node_Str");
  encoded=new int[]{1,1,0,0,0,0,0,0,0,0,0,0,1,0};
  decoded=se.decode(mem,encoded,"String_Node_Str");
  fieldsMap=decoded.getFields();
  assertEquals(1,fieldsMap.size());
  assertEquals(2,decoded.getRanges("String_Node_Str").size());
  assertEquals(decoded.getRanges("String_Node_Str").getRange(0).toString(),"String_Node_Str");
  encoded=new int[]{1,1,1,1,1,0,0,0,0,0,0,0,0,0};
  decoded=se.decode(mem,encoded,"String_Node_Str");
  fieldsMap=decoded.getFields();
  assertEquals(1,fieldsMap.size());
  assertEquals(1,decoded.getRanges("String_Node_Str").size());
  assertEquals(decoded.getRanges("String_Node_Str").getRange(0).toString(),"String_Node_Str");
  encoded=new int[]{1,1,1,0,0,0,0,0,1,1,1,1,0,0};
  decoded=se.decode(mem,encoded,"String_Node_Str");
  fieldsMap=decoded.getFields();
  assertEquals(1,fieldsMap.size());
  assertEquals(2,decoded.getRanges("String_Node_Str").size());
  assertEquals(decoded.getRanges("String_Node_Str").getRange(0).toString(),"String_Node_Str");
  assertEquals(decoded.getRanges("String_Node_Str").getRange(1).toString(),"String_Node_Str");
  encoded=new int[]{0,1,0,0,0,0,0,0,1,1,1,1,0,0};
  decoded=se.decode(mem,encoded,"String_Node_Str");
  fieldsMap=decoded.getFields();
  assertEquals(1,fieldsMap.size());
  assertEquals(2,decoded.getRanges("String_Node_Str").size());
  assertEquals(decoded.getRanges("String_Node_Str").getRange(0).toString(),"String_Node_Str");
  assertEquals(decoded.getRanges("String_Node_Str").getRange(1).toString(),"String_Node_Str");
}