Hi Angus
A prototype isn't an example of a question - rather, it defines a question type. See section 11 of the documentation. But I suggest you don't worry about prototypes for now. Wait until you've written a few questions yourself and have a better idea of how prototypes work.
Your example question is on the right track (though FYI the file you attached is lacking the <quiz> tag at the start). Testing scripts is always a bit messy compared to testing functions, because there are three phases to each test instead of two:
- Set up a context for the student. In your case this involves defining the value of x.
- Running the student answer in that context.
- Checking if the student answer did the right thing, i.e. that it left the workspace in the right state. In your case that means a new variable y must exist and must contain the correct value for the given x.
I see you've correctly used the testcode for step 1 and used the extra code for step 3. However, your template code doesn't actually make use of the extra code, so you're not actually doing anything after the student code has been run.
A better template for this question would be:
{{ TEST.testcode }};
format free
{{ STUDENT_ANSWER }}
{{ TEST.extra }}
With that change, using as an answer
y = x(5, :);
and tweaking the expected output a bit, the question sort of works. However, as you point out, it doesn't give very friendly feedback to the student. All they see are lines telling them the expected output was 1 and the actual output was 0, say.
A simpler approach would be to use disp(y) for the extra and then set the expected field to whatever the displayed slice value should be. However, you say that string comparisons aren't sufficiently robust, though I'm not quite sure why in this particular case, as I don't see any scope for rounding errors. But certainly you have to be careful of rounding errors in general, so then you have to write more elaborate tests. For example you might do a test like the following (in pseudocode):
if y not defined
print "You haven't defined y"
else if y != expected value within given tolerance
print "Your value of y is wrong."
print "Expected ... "
print "Got ..."
else
print "OK"
Sure, this gets tiresome very quickly, which is when you start writing your own question prototypes to abstract all the detail into the prototype.
There's also a problem with this approach if the student's code generates output, say because the student omitted the ';' from the end of the assignment statement. You should at least warn the student in the question that they mustn't print anything and must terminate their assignment statement with a semicolon. More elaborate approaches involve catching any student output yourself and giving an appropriate error message, but that is way too complicated for now.
Another thing that you're possibly doing wrong, if you're not getting any output at all, is running the question in the wrong mode. You should be running it in adaptive mode, and you must also make sure that the review options are set to display feedback during the attempt. Otherwise you or the student won't see the test results until the quiz is closed.
Hope that's enough to get you going again
Richard