Implement tree validation functions.

We should now be able to add structural validation tests for all functions.
This addresses in part  #59 .