Exercise 3.12: Implemented the reverse function with test.