Cody challenge hard coded answers
Mostrar comentarios más antiguos
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
Respuestas (1)
John D'Errico
el 15 de Nov. de 2020
Editada: John D'Errico
el 15 de Nov. de 2020
0 votos
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?
5 comentarios
Shlomo Geva
el 15 de Nov. de 2020
Rik
el 15 de Nov. de 2020
So you know what to do when creating a test set yourself.
I'm curious to know how you can see solutions that are shorter than yours. That is one of my major gripes with Cody: it prevents learning from people who may come up with better solutions or other approaches.
Shlomo Geva
el 16 de Nov. de 2020
John D'Errico
el 16 de Nov. de 2020
I said that myself, is that ALL Cody probblems should have a random test as one of the tests. Should any half decent programmer know how to do that? Well, yes. But the fact remains, Cody does not restrict anyone from submitting a problem. And that results in many problems with a terribly easy set of tests to game. Cody is what it is.
Walter Roberson
el 16 de Nov. de 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.)
Categorías
Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!