refactoring for next graph input test case
added a new test case and introduced logic to make both test cases pass