Added more tests to ring detection.

* Fixed a couple of cases with unintended logic.
* Added edge-case tests, which currently fail.