Added unit test code

Added unit test code, made lots of changes to namespaces, added a
run_all routine and code for R for unit testing. Lots of progress but
many more tests to add.