Functional Programming Principles in Scala, assignment 3

Fix bugs and add test case