Program: 4489
Project: 4489
Buggy source:
/** 
 * Temporary test to test basic sequence mechanisms
 */
@Test public void testBasicSetup_TemporalMemory_MANUAL_MODE(){
  Parameters p=NetworkTestHarness.getParameters();
  p.setParameterByKey(KEY.RANDOM,new MersenneTwister(42));
  final int[] input1=new int[]{0,1,0,0,0,1,0,1,0,0,0,1,1,0,0,0,1,0,0,0};
  final int[] input2=new int[]{0,1,0,0,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0};
  final int[] input3=new int[]{0,0,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0};
  final int[] input4=new int[]{0,0,1,1,0,0,0,0,1,1,0,0,1,0,0,0,0,1,1,0};
  final int[] input5=new int[]{0,0,1,1,0,0,0,0,1,0,0,0,1,0,0,0,0,1,1,0};
  final int[] input6=new int[]{0,0,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1};
  final int[] input7=new int[]{0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,0};
  final int[][] inputs={input1,input2,input3,input4,input5,input6,input7};
  int[] expected1={1,5,11,12,13};
  int[] expected2={2,3,11,12,13,14};
  int[] expected3={2,3,8,9,12,17,18};
  int[] expected4={1,2,3,5,7,8,11,12,16,17,18};
  int[] expected5={2,7,8,9,17,18,19};
  int[] expected6={1,7,8,9,17,18};
  int[] expected7={1,5,7,11,12,16};
  final int[][] expecteds={expected1,expected2,expected3,expected4,expected5,expected6,expected7};
  Layer<int[]> l=new Layer<>(p,null,null,new TemporalMemory(),null,null);
  int timeUntilStable=415;
  l.subscribe(new Observer<Inference>(){
    int test=0;
    int seq=0;
    @Override public void onCompleted(){
    }
    @Override public void onError(    Throwable e){
      e.printStackTrace();
    }
    @Override public void onNext(    Inference output){
      if (seq / 7 >= timeUntilStable) {
        assertTrue(Arrays.equals(expecteds[test],output.getSDR()));
      }
      if (test == 6)       test=0;
 else       test++;
      seq++;
    }
  }
);
  for (int j=0; j < timeUntilStable; j++) {
    for (int i=0; i < inputs.length; i++) {
      l.compute(inputs[i]);
    }
  }
  for (int j=0; j < 2; j++) {
    for (int i=0; i < inputs.length; i++) {
      l.compute(inputs[i]);
    }
  }
}

Fixed version (ground truth):
/** 
 * Temporary test to test basic sequence mechanisms
 */
@Test public void testBasicSetup_TemporalMemory_MANUAL_MODE(){
  Parameters p=NetworkTestHarness.getParameters();
  p.setParameterByKey(KEY.RANDOM,new MersenneTwister(42));
  final int[] input1=new int[]{0,1,0,0,0,1,0,1,0,0,0,1,1,0,0,0,1,0,0,0};
  final int[] input2=new int[]{0,1,0,0,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0};
  final int[] input3=new int[]{0,0,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0};
  final int[] input4=new int[]{0,0,1,1,0,0,0,0,1,1,0,0,1,0,0,0,0,1,1,0};
  final int[] input5=new int[]{0,0,1,1,0,0,0,0,1,0,0,0,1,0,0,0,0,1,1,0};
  final int[] input6=new int[]{0,0,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1};
  final int[] input7=new int[]{0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,0};
  final int[][] inputs={input1,input2,input3,input4,input5,input6,input7};
  int[] expected1={1,5,11,12,13};
  int[] expected2={2,3,11,12,13,14};
  int[] expected3={2,3,8,9,12,17,18};
  int[] expected4={2,3,8,12,17,18};
  int[] expected5={2,7,8,9,17,18,19};
  int[] expected6={1,7,8,9,17,18};
  int[] expected7={1,5,7,11,12,16};
  final int[][] expecteds={expected1,expected2,expected3,expected4,expected5,expected6,expected7};
  Layer<int[]> l=new Layer<>(p,null,null,new TemporalMemory(),null,null);
  int timeUntilStable=200;
  l.subscribe(new Observer<Inference>(){
    int test=0;
    int seq=0;
    @Override public void onCompleted(){
    }
    @Override public void onError(    Throwable e){
      e.printStackTrace();
    }
    @Override public void onNext(    Inference output){
      if (seq / 7 >= timeUntilStable) {
        System.out.println("String_Node_Str" + (seq) + "String_Node_Str"+ (test)+ "String_Node_Str"+ Arrays.toString(output.getSDR()));
        assertTrue(Arrays.equals(expecteds[test],output.getSDR()));
      }
      if (test == 6)       test=0;
 else       test++;
      seq++;
    }
  }
);
  for (int j=0; j < timeUntilStable; j++) {
    for (int i=0; i < inputs.length; i++) {
      l.compute(inputs[i]);
    }
  }
  for (int j=0; j < 2; j++) {
    for (int i=0; i < inputs.length; i++) {
      l.compute(inputs[i]);
    }
  }
}