# Cody challenge hard coded answers

2 views (last 30 days)
Shlomo Geva on 14 Nov 2020
Commented: Walter Roberson on 16 Nov 2020
I have been using something similar to the Cody Challenge problem solving rig for many years (albeit more sophisticated) in teaching various programming languages, including Matlab. While browsing through some Cody problems and solutions, I noticed that some solutions consist of just hard coded responsese to the test input.
For instance, a solution to problem 63 (decimal to roman conversion) encodes the test cases, and appears as a valid solution.
Cody is just for fun and someone probably decided to play silly buggers, but still, should this appear as a correct solution when it is not?
function romStr = dec2rom(n)
d = [1990, 2008, 1666, 49, 45, 0];
r = {'MCMXC', 'MMVIII', 'MDCLXVI', 'XLIX', 'XLV', ''};
romStr = r{d==n};
end

John D'Errico on 15 Nov 2020
Edited: John D'Errico on 15 Nov 2020
Should it?
Not really, but what are you going to do? A good problem should include at least one random test input. But that also implies the problem author knows how to solve the problem themselves, not always the case. Are all of the Cody problems well written, with good test cases? No. Such is life.
Is it really worth worrying about?
Walter Roberson on 16 Nov 2020
There are a lot of programmers who are terrible at writing tests. Programmers are quite prone to only thinking about something one way, and not realizing that other inputs are even possible let alone will cause a problem.
This is the reason that writing good test cases is an art: it takes skills to think of good ways to break a program.
But programmers tend to think that they have those skills, so it is common for programmers to look down on testers and refuse to cooperate with them. And then when the product ships with significant bugs because the testers could not get cooperation, it is the testers who get blamed. :(
(I know some professional testers.)