Different but correct results

Different but correct results

de către Вася Пупкин-
Număr de răspunsuri: 1

Hello

Suppose there is a task in which you need to output two numbers, for example, 1 and 2.
In this case, both the output "1 2" and "2 1" is considered correct.

Can you tell me how to make such a check?

Thanks

Ca răspuns la Вася Пупкин

Re: Different but correct results

de către Richard Lobb-
I recommend avoiding this situation if you can, e.g. by:

  1. Setting a 'write-a-function' question instead of a 'write-a-program' question. For example, ask the student to write a function that returns a list of numbers. The test code can then call the function and do its own checking, e.g. sorting the student's answer before comparing with the expected.
  2. Tightening the specification to require a specific ordering of the output.
Alternatively, you may also be able to use a regular expression grader instead of exact match. For the simple example you quote, the expected output might be set to something like \A(1 2)|(2 1)\s*\Z. But regular expression graders confuse students so this isn't usually a good approach.

If you really must ask a question in which the output needs to be passed through some custom validator, you'll need to use a template grader. See   https://github.com/trampgeek/moodle-qtype_coderunner#grading-with-templates. However, this is a big step up in complexity.