Browsing through GitHub i came across XSolve Code Kata repository. Code Kata #1 have two implementations (PHP, C#) of Roman numerals converter. I had some free time and wanted to implement Scala version. The result is on my GitHub.
I added Roman-Arabic conversion compared to XSolve solution. Project has full test coverage, what means every single line of code was executed at least once (love that fancy Travis and Coveralls badges).
What is being used:
- case classes
RomanNum, of course it could be int and string, but hey, Scala has rich typesystem ;-)
NumConverterclass is singleton object
- one pattern matching method
break()functions, which I find funny that Scala doesn’t have implemented such base things natively
FlatSpecfrom ScalaTest suite (BDD approach)
Be warned, validation function is ugly, contains nested IFs and needs refactoring, but as long as it passes tests it’s OK.
Whole code is not very „Scalish”. I consider myself as an Advanced Beginner on Scala according to Dreyfus Model and I don’t care ;-)