Implement excercise 3 with tests in Scala.