Skip to content

Commit

Permalink
fix: Added @ignore to the tests & refactored code a bit (#685)
Browse files Browse the repository at this point in the history
[no important files changed]
  • Loading branch information
DerSimeon authored Oct 20, 2024
1 parent c331e1c commit 5194fd0
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions exercises/practice/scale-generator/src/test/kotlin/ScaleTest.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import kotlin.test.Ignore
import kotlin.test.asserter
import kotlin.test.Test

Expand All @@ -10,131 +11,147 @@ class ScaleTest {
assertScalesEqual(expected, Scale("C").chromatic())
}

@Ignore
@Test
fun `chromatic scale with flats`() {
val expected = listOf("F", "Gb", "G", "Ab", "A", "Bb", "B", "C", "Db", "D", "Eb", "E")
assertScalesEqual(expected, Scale("F").chromatic())
}

// Test scales with specified intervals
@Ignore
@Test
fun `simple major scale`() {
val expected = listOf("C", "D", "E", "F", "G", "A", "B")
assertScalesEqual(expected, Scale("C").interval("MMmMMMm"))
}

@Ignore
@Test
fun `major scale with sharps`() {
val expected = listOf("G", "A", "B", "C", "D", "E", "F#")
assertScalesEqual(expected, Scale("G").interval("MMmMMMm"))
}

@Ignore
@Test
fun `major scale with flats`() {
val expected = listOf("F", "G", "A", "Bb", "C", "D", "E")
assertScalesEqual(expected, Scale("F").interval("MMmMMMm"))
}

@Ignore
@Test
fun `minor scale with sharps`() {
val expected = listOf("F#", "G#", "A", "B", "C#", "D", "E")
assertScalesEqual(expected, Scale("f#").interval("MmMMmMM"))
}

@Ignore
@Test
fun `minor scale with flats`() {
val expected = listOf("Bb", "C", "Db", "Eb", "F", "Gb", "Ab")
assertScalesEqual(expected, Scale("bb").interval("MmMMmMM"))
}

@Ignore
@Test
fun `dorian mode`() {
val expected = listOf("D", "E", "F", "G", "A", "B", "C")
assertScalesEqual(expected, Scale("d").interval("MmMMMmM"))
}

@Ignore
@Test
fun `mixolydian mode`() {
val expected = listOf("Eb", "F", "G", "Ab", "Bb", "C", "Db")
assertScalesEqual(expected, Scale("Eb").interval("MMmMMmM"))
}

@Ignore
@Test
fun `lydian mode`() {
val expected = listOf("A", "B", "C#", "D#", "E", "F#", "G#")
assertScalesEqual(expected, Scale("a").interval("MMMmMMm"))
}

@Ignore
@Test
fun `phrygian mode`() {
val expected = listOf("E", "F", "G", "A", "B", "C", "D")
assertScalesEqual(expected, Scale("e").interval("mMMMmMM"))
}

@Ignore
@Test
fun `locrian mode`() {
val expected = listOf("G", "Ab", "Bb", "C", "Db", "Eb", "F")
assertScalesEqual(expected, Scale("g").interval("mMMmMMM"))
}

@Ignore
@Test
fun `harmonic minor`() {
val expected = listOf("D", "E", "F", "G", "A", "Bb", "Db")
assertScalesEqual(expected, Scale("d").interval("MmMMmAm"))
}

@Ignore
@Test
fun octatonic() {
val expected = listOf("C", "D", "D#", "F", "F#", "G#", "A", "B")
assertScalesEqual(expected, Scale("C").interval("MmMmMmMm"))
}

@Ignore
@Test
fun hexatonic() {
val expected = listOf("Db", "Eb", "F", "G", "A", "B")
assertScalesEqual(expected, Scale("Db").interval("MMMMMM"))
}

@Ignore
@Test
fun pentatonic() {
val expected = listOf("A", "B", "C#", "E", "F#")
assertScalesEqual(expected, Scale("A").interval("MMAMA"))
}

@Ignore
@Test
fun enigmatic() {
val expected = listOf("G", "G#", "B", "C#", "D#", "F", "F#")
assertScalesEqual(expected, Scale("G").interval("mAMMMmm"))
}

fun assertScalesEqual(expected: List<String>, actual: List<String>) {
private fun assertScalesEqual(expected: List<String>, actual: List<String>) {
asserter.assertTrue(
{ "Scales should be equal. Expected <$expected>, actual <$actual>" },
scalesAreEqual(expected, actual))
}

fun scalesAreEqual(expected: List<String>, actual: List<String>): Boolean {
private fun scalesAreEqual(expected: List<String>, actual: List<String>): Boolean {
if (expected.size != actual.size) return false
return expected.zip(actual, this::notesEqual).all { it }
}

// Few enough equal notes that we can just list them all
fun notesEqual(left: String, right: String) = left.equals(right) || when(left) {
fun notesEqual(left: String, right: String) = left == right || when(left) {
// A# == Bb
"A#" -> right.equals("Bb")
"Bb" -> right.equals("A#")
"A#" -> right == "Bb"
"Bb" -> right == "A#"
// C# == Db
"C#" -> right.equals("Db")
"Db" -> right.equals("C#")
"C#" -> right == "Db"
"Db" -> right == "C#"
// D# == Eb
"D#" -> right.equals("Eb")
"Eb" -> right.equals("D#")
"D#" -> right == "Eb"
"Eb" -> right == "D#"
// F# == Gb
"F#" -> right.equals("Gb")
"Gb" -> right.equals("F#")
"F#" -> right == "Gb"
"Gb" -> right == "F#"
// G# == Ab
"G#" -> right.equals("Ab")
"Ab" -> right.equals("G#")
"G#" -> right == "Ab"
"Ab" -> right == "G#"
else -> false
}
}

0 comments on commit 5194fd0

Please sign in to comment.