### Question:
MelodicExtractor { public int getCurrentBarIndex(int barCount, int currentBar, int index){ switch (barCount){ case 1: return 0; case 2: if(index < 4){ return 0; }else if(index >=4 && index <8){ return 1; }else if(index >=8 && index <12){ return 0; }else if(index >= 12 && index <16){ return 1; }else{ throw new RuntimeException("ERROR getCurrentBarIndex out of bound index : " + index); } case 4: if(index < 4){ return 0; }else if(index >=4 && index <8){ return 1; }else if(index >=8 && index <12){ return 2; }else if(index >= 12 && index <16){ return 3; }else{ throw new RuntimeException("ERROR getCurrentBarIndex out of bound index : " + index); } default: throw new RuntimeException("ERROR getCurrentBarIndex bar count - " + barCount); } }  QueueState extractedAndSetHarmony(QueueState queueState); List<HarmonyExtraction> createHarmonicExtractionForBar(ProgressionUnitBar progressionUnitBar); HarmonyExtraction extractedAndSetHarmony(ProgressionUnitBar progressionUnitBar, int noteIndex); int getCurrentBarIndex(int barCount, int currentBar, int index);  }### Answer:
@Test public void shouldGetCurrentBarFor2BarLoops(){ int resultOne = melodicExtractor.getCurrentBarIndex(2, 1, 3); int resultTwo = melodicExtractor.getCurrentBarIndex(2, 2, 7); int resultThree = melodicExtractor.getCurrentBarIndex(2, 3, 11); int resultFour = melodicExtractor.getCurrentBarIndex(2, 4, 15); assertThat(resultOne).isEqualTo(0); assertThat(resultTwo).isEqualTo(1); assertThat(resultThree).isEqualTo(0); assertThat(resultFour).isEqualTo(1); }
@Test public void shouldGetCurrentBarFor1BarLoops(){ int resultOne = melodicExtractor.getCurrentBarIndex(1, 1, 1); assertThat(resultOne).isEqualTo(0); }
@Test public void shouldGetCurrentBarFor4BarLoops() { int resultOne = melodicExtractor.getCurrentBarIndex(4, 4, 13); assertThat(resultOne).isEqualTo(3); }