what to do with a flawed C++ skills test
- by Mike Landis
In the following gcc.gnu.org post, Nathan Myers says that a C++ skills test at SANS Consulting Services contained three errors in nine questions:
Looking around, one of fthe first on-line C++ skills tests I ran across was:
http://www.geekinterview.com/question_details/13090
I looked at question 1...
find(int x,int y)
{ return ((x<y)?0:(x-y)):}
call find(a,find(a,b)) use to find
(a) maximum of a,b
(b) minimum of a,b
(c) positive difference of a,b
(d) sum of a,b
... immediately wondering why would anyone write anything so obtuse. Getting past the absurdity, I didn't really like any of the answers, immediately eliminating (a) and (b) because you can get back zero (which is neither a nor b) in a variety of circumstances. Sum or difference seemed more likely, except that you could also get zero regardless of the magnitudes of a and b. So... I put Matlab to work (code below) and found: when either a or b is negative you get zero; when b a you get a; otherwise you get b, so the answer is (b) min(a,b), if a and b are positive, though strictly speaking the answer should be none of the above because there are no range restrictions on either variable. That forces test takers into a dilemma - choose the best available answer and be wrong in 3 of 4 quadrants, or don't answer, leaving the door open to the conclusion that the grader thinks you couldn't figure it out.
The solution for test givers is to fix the test, but in the interim, what's the right course of action for test takers? Complain about the questions?
function z = findfunc(x,y)
for i=1:length(x)
if x(i) < y(i)
z(i) = 0;
else
z(i) = x(i) - y(i);
end
end
end
function [b,d1,z] = plotstuff()
k = 50;
a = [-k:1:k];
b = (2*k+1) * rand(length(a),1) - k;
d1 = findfunc(a,b);
z = findfunc(a,d1);
plot( a, b, 'r.', a, d1, 'g-', a, z, 'b-');
end