A teacher asked me the following question:
I had this silly question in a tutorial for absolute beginners to get a feeling of the Pascal syntax:
Write a program to print a "visiting card" similar to this:
------------------------------ 25/D, Gamanarambha Veediya Kosmadalawa 12450 ------------------------------
-
- The output has four lines
- Lines 1 and 4: any number of hyphens
- Lines 2 and 3: any text, can't be empty
program printVisitingCard; begin WriteLn('-----------------------'); WriteLn(' Gemunu Jayawarsiri'); WriteLn(' 24B, Talawatugoda Road'); WriteLn('-----------------------'); end.
You can't use the default 'exact match' grader on questions of this sort. You must either use a regular expression grader or write your own custom grader that intercepts the output and prints helpful messages like "I expected 4 lines but got only 3". Custom graders are a lot more work and are not usually worth the effort except when you are creating a new question type that you wish to use repeatedly.
To specify the expected answer with a regular expression you must click the Customise checkbox and then select Regular Expression from the Grading dropdown. The enter the regular expression you want into the test case's Expected field. The in-line help explains a bit about the required syntax.
In the example above, a possible regular expression is:
\A-+\n.+\n.+\n-+\Z
Here, \A matches the start of the output and \Z matches the end. Note that there is no newline at the end of the expected output because CodeRunner strips all trailing white space from the output, as well as any trailing white space on each line.
BUT: I prefer to avoid questions that require a regular expression grader, as the students don't understand the result table "Expected" column, and the Show Differences button isn't available. It's nearly always easier to ask students to write programs that generate precisely-specified output. That might seem overly fussy, but programming is like that. The compilers/interpreters are fussy about requiring precise syntax in the program, so why not be equally fussy about requiring exact output?
Hiding the regular expression
As a final comment, if you do wish to use regular expression grading but don't want the students to see the regular expression you're using, you can hide the Expected column from the result table by setting a custom value for the Result columns field in the (customised) question authoring form. That means you won't confuse the students by showing them the regular expression. Instead, they will be confused when they get marked wrong but don't know why!
However, with small classes, and a teacher on hand to help, that might be quite acceptable.
The default value of the Result columns field is
[["Test", "testcode"],["Input", "stdin"], ["Expected", "expected"], ["Got", "got"]]
To hide the Expected column, set the field to
[["Test", "testcode"],["Input", "stdin"], ["Got", "got"]]
Note that empty columns are not displayed in the result table, so in fact only the Got column would appear in the above question, which would look like this: