Add unit tests

Well, they're not really unit tests since they only test the public interface at the highest level. But still.