add test and code for Problem 5