add test and code for problem 8