Updated the code with sample test case