Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Added @Ignore to the tests & refactored code a bit #685

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}