python3 solution of 1-6 + unit testing