### Question:
FrequencyToPitchConversion { public String getPitchName(float freq){ float closestDistance = 9999999f; PitchFreq bestMatch = null; for(PitchFreq pitchFreq:pitchFreqs) { int numOfOctaves = 8; for (int i = 0; i < numOfOctaves+1; i++) { double freqOctave = pitchFreq.getFreq() * Math.pow((double)2f,(double)i); if(Math.abs(freq-freqOctave) < closestDistance){ bestMatch = pitchFreq; bestMatch.setOctave(i); closestDistance = (float)Math.abs(freq-freqOctave); } } } return bestMatch.getNote(); } FrequencyToPitchConversion(); String getPitchName(float freq);  }### Answer:
@Test public void shouldReturnCNote(){ String pitchOne = frequencyToPitchConversion.getPitchName(16.35f); String pitchTwo = frequencyToPitchConversion.getPitchName(31.96f); String pitchThree = frequencyToPitchConversion.getPitchName(4185.01f); assertThat(pitchOne).isEqualTo("c"); assertThat(pitchTwo).isEqualTo("c"); assertThat(pitchThree).isEqualTo("c"); }
@Test public void shouldReturnBNote(){ String pitchOne = frequencyToPitchConversion.getPitchName(31f); String pitchTwo = frequencyToPitchConversion.getPitchName(122f); String pitchThree = frequencyToPitchConversion.getPitchName(7901.13f); assertThat(pitchOne).isEqualTo("b"); assertThat(pitchTwo).isEqualTo("b"); assertThat(pitchThree).isEqualTo("b"); }
@Test public void shouldReturnFSharpNote(){ String pitchOne = frequencyToPitchConversion.getPitchName(23f); String pitchTwo = frequencyToPitchConversion.getPitchName(186.1f); String pitchThree = frequencyToPitchConversion.getPitchName(5920f); assertThat(pitchOne).isEqualTo("fs"); assertThat(pitchTwo).isEqualTo("fs"); assertThat(pitchThree).isEqualTo("fs"); }