protected static function tidy($s) { if ($s === null) { return null; } else { $cleanS = qtype_coderunner_grader::clean($s); return qtype_coderunner_grader::snip($cleanS); } }
/** Called to grade the output generated by a student's code for * a given testcase. Returns a single TestResult object. * Should not be called if the execution failed (syntax error, exception * etc). */ function grade_known_good(&$output, &$testCase) { $regex = '/' . str_replace('/', '\\/', $testCase->expected) . '/ms'; $isCorrect = preg_match($regex, $output); $awardedMark = $isCorrect ? $testCase->mark : 0.0; if (isset($testCase->stdin)) { $resultStdin = qtype_coderunner_grader::tidy($testCase->stdin); } else { $resultStdin = null; } return new qtype_coderunner_test_result(qtype_coderunner_grader::tidy($testCase->testcode), $testCase->mark, $isCorrect, $awardedMark, qtype_coderunner_grader::snip($testCase->expected), qtype_coderunner_grader::snip($output), $resultStdin, qtype_coderunner_grader::tidy($testCase->extra)); }
/** This grader tests if the expected output matches the actual * output after removing all empty lines and trailing white space, * collapsing all sequences of space or tab characters to a single * space and converting all letters to lower case. [These changes * are of course applied to both expected and actual outputs.] * * As requested by Ulrich Dangel. */ function grade_known_good(&$output, &$testCase) { $cleanedOutput = qtype_coderunner_grader::clean($output); $cleanedExpected = qtype_coderunner_grader::clean($testCase->expected); $isCorrect = $this->reduce($cleanedOutput) == $this->reduce($cleanedExpected); $awardedMark = $isCorrect ? $testCase->mark : 0.0; if (isset($testCase->stdin)) { $resultStdin = qtype_coderunner_grader::tidy($testCase->stdin); } else { $resultStdin = null; } return new qtype_coderunner_test_result(qtype_coderunner_grader::tidy($testCase->testcode), $testCase->mark, $isCorrect, $awardedMark, qtype_coderunner_grader::snip($cleanedExpected), qtype_coderunner_grader::snip($cleanedOutput), $resultStdin, qtype_coderunner_grader::tidy($testCase->extra)); }