Add better tests for depth().
Fix broken depth() calculation.