Added a function to test the shortest path