Add tests for generating unit ids correctly

I didn't test for insertion codes and the like to make sure that we generated
the unit ids correctly. This commit fixes that by adding such code. In addition,
I change the UnitIdGenerator so that it can deal with None in the object it is
given. Before it would try to add it to the id, which is not good.