diff --git a/app/src/test/java/com/nicobrailo/pianoli/melodies/NoteMapperTest.java b/app/src/test/java/com/nicobrailo/pianoli/melodies/NoteMapperTest.java index 89fa9b6..37ab8fc 100644 --- a/app/src/test/java/com/nicobrailo/pianoli/melodies/NoteMapperTest.java +++ b/app/src/test/java/com/nicobrailo/pianoli/melodies/NoteMapperTest.java @@ -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.*; @@ -19,6 +22,41 @@ public void noteRangeLimits() { } + + static List allNotesSource() { + List octaves = List.of("1", "2"); + List baseNotes = List.of("C", "D", "E", "F", "G", "A", "B"); + List modifiers = List.of("b", "", "#"); // ordered to keep resulting indexes in ascending order + + ArrayList 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) {