Tests for units

Added tests for the units section and fixed some bugs in the code that
the tests showed.