Skip to content

Commit

Permalink
Add (still failing) all possible notes test for NoteMapper coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jules Kerssemakers committed Jan 9, 2024
1 parent 1b59b50 commit 45fda60
Showing 1 changed file with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.jupiter.params.provider.*;

import java.util.ArrayList;
import java.util.List;

import static com.nicobrailo.pianoli.melodies.NoteMapper.NO_NOTE;
import static com.nicobrailo.pianoli.melodies.NoteMapper.get_key_idx_from_note;
import static org.junit.jupiter.api.Assertions.*;

Expand All @@ -19,6 +22,41 @@ public void noteRangeLimits() {

}


static List<Arguments> allNotesSource() {
List<String> octaves = List.of("1", "2");
List<String> baseNotes = List.of("C", "D", "E", "F", "G", "A", "B");
List<String> modifiers = List.of("b", "", "#"); // ordered to keep resulting indexes in ascending order

ArrayList<Arguments> result = new ArrayList<>(42);

// loop order differs from notation order, to keep notes in roughly ascending order
for (String octave: octaves) {
for (String base: baseNotes) {
for (String modifier: modifiers) {
String note = base + modifier + octave;

// special handling for notes outside our range limits, which the combinator could create
switch (note) {
case "Cb1": continue; // before first possible key; Keyboard starts at C1.
case "B#2": continue; // after last possible key; We don't have sound samples beyond B2.
}

result.add(Arguments.of(note));
}
}
}
return result;
}

@ParameterizedTest
@MethodSource("allNotesSource")
public void allNotesWork(String note) {
int idx = get_key_idx_from_note(note);

assertNotEquals(NO_NOTE, idx);
}

@ParameterizedTest
@ValueSource(strings = {"C#1", "Db1", "D♭1"})
public void fancySynonyms(String note) {
Expand Down

0 comments on commit 45fda60

Please sign in to comment.