formatted the code and added test case