Depth-first traversal and tests