I have just solved the Secret Handling exercise in the C track. The solution function is declared in the form of:
const char** commands(size_t number);
The value returned by the function is supposed to be an array of actions (character strings) of the size depending on number.
I see a couple of problems in this exercise.
- Despite that the size of the returned array can be any number between zero and four, the
commandsfunction does not pass back the array size. This makes it nearly impossible for the tests to check the array size. - The tests in
test_secret_handshake.cactually assumes that the returned array has the correct size, unless no action is expected to be returned (in such case, the tests require that the first element in the array beNULL).
For example, the first test in test_secret_handshake.c expects [“wink”] to be returned from the solution. It, however, gives a pass to any among [“wink”], [“wink”, NULL, NULL, NULL], [“wink”, “double wink”, “close your eyes”, “jump”], [“wink”, “jump”, “jump”, “jump”], etc. I think that the tests should be a bit more tighter.
A possible fix is to change the solution function to:
const char** commands(size_t number, size_t* size);
and let the solution set *size to the size of the array. But this makes all exiting solutions invalid.
Another possible fix is to assume that the size of the returned array is always four, and require that the remaining slots must be filled with NULL. In the first test case, the correct solution would be ["wink", NULL, NULL, NULL]. This is at least consistent with what the current tests do. Also, all existing solutions I have randomly picked seem to be able to survive through this change.