Implement excercise 4 with tests in Scala.