Refactored ring pruning logic to make it easier to read.

* Ring detection tests now produce more readable output.
* Ring detection tests now have assertions on the number of rings.