forked from nicolasbrailo/PianOli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test NoteMapper helper with JUnit 5/Jupiter.
Needs some additional plugins, because Google isn't moving on JUnit 5 support see - Google tracking issue: android/android-test#224 - Android <-> JUnit 5 plugin https://github.com/mannodermaus/android-junit5 - StackOverflow answer about the plugin https://stackoverflow.com/questions/46161113/junit-5-for-android-testing
- Loading branch information
Jules Kerssemakers
committed
Sep 8, 2023
1 parent
c9ec021
commit a506151
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/src/test/java/com/nicobrailo/pianoli/melodies/NoteMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.nicobrailo.pianoli.melodies; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static com.nicobrailo.pianoli.melodies.NoteMapper.get_key_idx_from_note; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
class NoteMapperTest { | ||
|
||
@Test | ||
public void noteRangeLimits() { | ||
assertEquals(0, get_key_idx_from_note("C1"), | ||
"lowest parsable note should be parsed"); | ||
assertEquals(26, get_key_idx_from_note("B2"), | ||
"lowest parsable note should be parsed"); | ||
|
||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"C#1", "Db1", "D♭1"}) | ||
public void fancySynonyms(String note) { | ||
assertEquals(1, get_key_idx_from_note(note), | ||
"all synonyms for the same note should work, including fancy symbols"); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"", " ", "fooooooo"}) | ||
public void noNoteFallback(String notANote) { | ||
assertEquals(5, get_key_idx_from_note(notANote), | ||
"non-existing notes should fall back to the not-a-note special value"); | ||
} | ||
|
||
@Test | ||
public void nullSafe() { | ||
assertEquals(5, get_key_idx_from_note(null), | ||
"Notemapper should gracefully handle null"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters