src/ch5/ex12: refactor and add test.