Hi all,
I've made a lot of progress in automatic question generation using Matlab (where I generate about 30 variations of each question), and am now getting into the more complex questions where the students write functions.
I have a Matlab file that generates the XML which I then import to CodeRunner/Moodle. This sets up the random question varients. I also write the function that serves as the correct answer. What I've been doing is, in the 'extras' section I use my function to generate the correct output and then write that into the XML so that I can use Octave's 'assert' function to compare the students' outputs.
In XML, this looks like:
<extra>
<text>try inData = struct; inData.adult=2;inData.children=2;inData.pensioner=2;inData.infant=2;[a{1:2}] = zooEntryCalculator(inData);studentCost = cost; stuBreakdown = a{2}'; breakdown= [10.6 0 24.14 23.64 6.68] assert(studentCost, cost); assert(breakDown, stuBreakDown); disp('OK') catch disp('WRONG'); end</text>
where the numerical matrix is the output of my program, inputted to CodeRunner/Moodle as a string.
This is very kludgy, and I feel like there must be a better way. I really want to avoid text-matching outputs, as I find that it doesn't work reliably, and I like being able to use Octave's unit-testing framework, but as the function outputs become more complex, it's harder to compare them. For example, if a function outputs a struct, are there any better options?
What would be ideal would be to somehow define my own function in the extra code section, then do head-to-head tests (my function vs the students') -- but I can't see how to do that elegantly.
Any suggestions welcome!
Cheers, Angus