Implement tree validation functions.

We should now be able to add structural validation tests for all functions.