Add unit tests for getnextcomp.
Adapt getnextcomp to coding style.