package io.sease.ra | |
import org.scalatest.FlatSpec | |
class IntervalsTableSpecs extends FlatSpec { | |
"The Intervals Table" should "return zero (min value) when start and end note are the same" in { | |
val pipeline = new IntervalsTable() | |
0 to 11 by 1 foreach (idx => | |
assert(pipeline.distanceBetween(idx, idx) == 0)) | |
} | |
it should "return 1 when start and end are subsequent" in { | |
val pipeline = new IntervalsTable() | |
0 to 11 by 1 foreach (idx => | |
assert(pipeline.distanceBetween(idx, if (idx == 11) 0 else idx + 1) == 1)) | |
11 to 0 by -1 foreach (idx => | |
assert(pipeline.distanceBetween(idx, if (idx == 11) 0 else idx + 1) == 1)) | |
} | |
it should "return 2 when the interval is one tone" in { | |
val pipeline = new IntervalsTable() | |
0 to 10 by 2 foreach (idx => | |
assert(pipeline | |
.distanceBetween(idx, if (idx >= 10) (10 - idx) else idx + 2) == 2)) | |
11 to 0 by -2 foreach (idx => | |
assert(pipeline | |
.distanceBetween(idx, if (idx >= 10) (11 - idx) + 1 else idx + 2) == 2)) | |
} | |
it should "return 11 (max value) when the interval is between a not and the preceeding" in { | |
val pipeline = new IntervalsTable() | |
0 to 10 by 2 foreach (idx => | |
assert( | |
pipeline.distanceBetween(idx, if (idx == 0) 11 else idx - 1) == 11)) | |
} | |
it should "throw an exception in case the lower bound is lesser than 0" in { | |
val pipeline = new IntervalsTable() | |
assertThrows[IllegalArgumentException] { | |
pipeline.distanceBetween(-1, 8); | |
} | |
} | |
it should "throw an exception in case the lower bound is greater than 11" in { | |
val pipeline = new IntervalsTable() | |
assertThrows[IllegalArgumentException] { | |
pipeline.distanceBetween(12, 8); | |
} | |
} | |
it should "throw an exception in case the higher bound is lesser than 0" in { | |
val pipeline = new IntervalsTable() | |
assertThrows[IllegalArgumentException] { | |
pipeline.distanceBetween(8, -1); | |
} | |
} | |
it should "throw an exception in case the higher bound is greater than 11" in { | |
val pipeline = new IntervalsTable() | |
assertThrows[IllegalArgumentException] { | |
pipeline.distanceBetween(8, 12); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment