Chapter 3 - updated implementation and test for function 'depth'