How to test that a function doesn't infinite loop

You’re question is actually touching on a very fundamental problem “halting problem”.
However in your case it is possible to help ensure the loop exits eventually. Things like timeouts, Max depth counters and checking for loops in the current planned path come to mind.
Another thing that comes to mind is to try and break down the complexity of the algorithm, so you can test smaller chunks of it ( possibly without the need of the loop/recursive behavior wrapping it)
Just some ideas.

2 Likes