ctp.py: moved code into main function

This makes it easier to execute the script from an import
ctp.py: bugfix: empty lines would cause error
test_ctp.py: split tests into several classes

Gave each function it's own class so the tests could
be split into more functions. This allows the function
names to be more descriptive, which makes it easier to
locate errors when tests fail.