Last active
March 7, 2019 06:03
-
-
Save ishideo/fc524b1a49162a032ab7275ec45e90d7 to your computer and use it in GitHub Desktop.
sbt "runMain KatakanaRomajiConvert.Main キョウト"
This file contains hidden or 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
lazy val root = (project in file(".")). | |
settings( | |
inThisBuild(List( | |
scalaVersion := "2.12.7", | |
version := "0.1.0-SNAPSHOT" | |
)), | |
name := "KatakanaRomajiConvert", | |
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % Test, | |
libraryDependencies += "com.ibm.icu" % "icu4j" % "63.1", | |
) |
This file contains hidden or 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
package KatakanaRomajiConvert | |
import com.ibm.icu.text.Transliterator | |
class KatakanaRomajiConvert(val word: String = "") { | |
private val transliterator = Transliterator.getInstance("Katakana-Latin") | |
def toRomaji: String = { | |
val kana: Option[String] = Some(word) | |
transliterator.transliterate(kana.getOrElse("")) | |
} | |
} | |
object Main extends App { | |
if (args.length != 0) { | |
val katakana: String = args(0) | |
val katakanaObj = new KatakanaRomajiConvert(katakana) | |
println(katakanaObj.toRomaji) | |
} else { | |
println("") | |
} | |
} |
This file contains hidden or 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
package KatakanaRomajiConvert | |
import org.scalatest._ | |
class KatakanaRomajiConvertSpec extends FlatSpec with Matchers { | |
"Input strings \"トウキョウ\"" should "output strings toukyou" in { | |
new KatakanaRomajiConvert("トウキョウ").toRomaji shouldEqual "toukyou" | |
} | |
"Input no string" should "" in { | |
new KatakanaRomajiConvert("").toRomaji shouldEqual "" | |
} | |
"Argument is null" should "" in { | |
new KatakanaRomajiConvert(null).toRomaji shouldEqual "" | |
} | |
"No argument" should "" in { | |
new KatakanaRomajiConvert().toRomaji shouldEqual "" | |
} | |
"Input strings \"あいうアイウabcABC\"" should "" in { | |
new KatakanaRomajiConvert("あいうアイウabcABC").toRomaji shouldEqual "あいうaiuabcABC" | |
} | |
"Input strings \"あいう アイウ abc ABC\"" should "" in { | |
new KatakanaRomajiConvert("あいう アイウ abc ABC").toRomaji shouldEqual "あいう aiu abc ABC" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment