This is an implementation of assignment 2 with test function.