Add tests for duplicate detection

There's not an easy way to test for infinite loops other than
making the test suite hang, unfortunately.