Skip to content
Permalink
Browse files

5 is written as V

  • Loading branch information
michaelbannister committed Jul 10, 2016
1 parent bdc01e4 commit 3d54827e666b1e073c1eb41cc4820915de48c654
Showing with 8 additions and 2 deletions.
  1. +6 −1 src/main/kotlin/RomanNumerals.kt
  2. +2 −1 src/test/kotlin/DecimalToRomanConverterTest.kt
@@ -3,7 +3,11 @@ private val powersOfTen = listOf(1000, 100, 10, 1)
fun Int.toRoman(): String {
val placeValues = toDecimalPlaceValues(this)
return placeValues.map {
it.magnitude.toRomanDigit().repeat(it.multiplier)
if (it.multiplier == 5) {
5.toRomanDigit()
} else {
it.magnitude.toRomanDigit().repeat(it.multiplier)
}
}.joinToString(separator = "")
}

@@ -25,6 +29,7 @@ private fun Int.toRomanDigit(): String = when(this) {
1000 -> "M"
100 -> "C"
10 -> "X"
5 -> "V"
1 -> "I"
else -> throw RomanNumeralException("No mapping to symbol for ${this}")
}
@@ -26,7 +26,8 @@ class DecimalToRomanConverterTest {
arrayOf(1000, "M"),
arrayOf(2000, "MM"),
arrayOf(11, "XI"),
arrayOf(3012, "MMMXII") // I didn't expect this to fail, just checking
arrayOf(3012, "MMMXII"), // I didn't expect this to fail, just checking
arrayOf(5, "V")
)

@Test

0 comments on commit 3d54827

Please sign in to comment.
You can’t perform that action at this time.