Good question. Sometimes you know it’s not right, but you’re not sure exactly what it’s supposed to do. This is particularly applicable when it’s an edge case. You’ll need to attempt to understand the requirements.
In my experience, understanding the requirements is not particularly easy for legacy projects. It could be just as tough for Open Source projects; especially those where no one’s actually bothered to document the requirements.