optimized ch3 challenge 3.test.cpp, made more versatile