Question Authors' Forum

Expected solution computed with a call to teacher function

Expected solution computed with a call to teacher function

by Yves Noel -
Number of replies: 1
Hi, I am using CodeRunner with octave function question type. I'm able to use template parameters to generate randomized call to test the student function but I'm not able to specify that the call to the student function (with randomized arguments) has to be compared with the call to the teacher function (sample answer field) with the same (randomized) arguments. I have tried to fill expected output with a call to the teacher solution function but it does not work. The teacher function seems to be used only for the "validate on save" option. Am I missing something or is it impossible ? Thank you for your precious help. Yves PS: I can send the xml file if it helps
In reply to Yves Noel

Re: Expected solution computed with a call to teacher function

by Richard Lobb -

Using the sample answer as a reference solution with which to test the student's submission isn't impossible but it is a bit difficult. CodeRunner was originally built to mimic a "test-driven development" model of programming: "here are all the tests, now write the program". In software engineering you don't usually have a reference solution to test against!

However, it is possible to use the sample answer for testing and indeed we sometimes do this. The template for the question is usually written in a scripting language like Python, along the lines of the "c_via_python" question type supplied with CodeRunner and documented here. The sample answer is available to the Twig template author as {{ QUESTION.answer }} (see here). So the template can first run that code, collect the output, then run the student answer and compare the two outputs. It requires quite a lot of CodeRunner experience to get this all working, though. And you need to be very sure that your sample answer is correct, as there's now no built-in validation.

Note that if you adopt this approach in conjunction with randomisation, you still have a problem with presenting the student with a "For example" table. You usually need to construct at least one or two sample answers with Twig code. If you wished to use your sample answer to generate the example table, the job would have to be sent to the Jobe server before the question could be displayed to the student. In large tests and exams, with multiple questions displayed on each page, that approach would result in hundreds or even thousands of jobs hitting the Jobe server in the first few seconds of the exam, which is why I don't support such a capability.