Skip to content

Commit

Permalink
Refactoring and bug fixing with new serialisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
trampgeek committed May 13, 2024
1 parent 0810a87 commit c6e559a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
6 changes: 3 additions & 3 deletions classes/combinator_grader_outcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private function format_first_failing_test($correctcol) {
* a button to copy the 'got' column into the 'expected' column of the test
* case.
*/
private function make_validation_fail_table($correctcol, $expectedcol, $gotcol, $sanitise) {
private function combinator_validation_failures($correctcol, $expectedcol, $gotcol, $sanitise) {
$error = '';
$rownum = 0;
$codecol = array_search(get_string('testcolhdr', 'qtype_coderunner'), $this->testresults[0]);
Expand All @@ -285,7 +285,7 @@ private function make_validation_fail_table($correctcol, $expectedcol, $gotcol,
}
$rownum += 1;
}
return html_writer::table($this->failures) . get_string('replaceexpectedwithgot', 'qtype_coderunner');
return $this->validation_failures_table();
}


Expand Down Expand Up @@ -341,7 +341,7 @@ public function validation_error_message() {
// copy-got-to-expected button.

$sanitise = !$this->is_html_column($gotcol);
$error .= $this->make_validation_fail_table($correctcol, $expectedcol, $gotcol, $sanitise);
$error .= $this->combinator_validation_failures($correctcol, $expectedcol, $gotcol, $sanitise);
} else if ($correctcol) {
// Can't use the fancy table presentation as missing got and/or
// expected. So just make a simple 'first failing test' string.
Expand Down
42 changes: 28 additions & 14 deletions classes/testing_outcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ class qtype_coderunner_testing_outcome {
/** @var string For use by combinator template graders, allowing to customise grade and feedback. */
public $graderstate;

/** @var html_table Table for reporting validation errors. */
public $failures;
/** @var array Table for reporting validation errors. */
public $failuresdata;

/** @var array Table for reporting validation errors. */
public $failuresrowclasses;

public function __construct($maxpossmark, $numtestsexpected, $isprecheck) {
$this->status = self::STATUS_VALID;
Expand Down Expand Up @@ -313,24 +316,35 @@ public function validation_error_message() {
}
$message = get_string('failedntests', 'qtype_coderunner', [
'numerrors' => $this->numerrors]);
if ($this->failuresdata) {
$htmltable = new html_table();
$htmltable->attributes['class'] = 'coderunner-test-results';
$htmltable->head = [
get_string('testcolhdr', 'qtype_coderunner'),
get_string('expectedcolhdr', 'qtype_coderunner'),
get_string('gotcolhdr', 'qtype_coderunner'),
];
$htmltable->data = $this->failuresdata;
$htmltable->rowclasses = $this->failuresrowclasses;
$message .= html_writer::table($htmltable) . get_string('replaceexpectedwithgot', 'qtype_coderunner');
}
$message .= $this->validation_failures_table();
} else {
$message = get_string('failedtesting', 'qtype_coderunner');
}
return $message . html_writer::empty_tag('br') . get_string('howtogetmore', 'qtype_coderunner');
}


/**
* Build an HTML table of all the validation failures.
* @return string An HTML table containing all the failures, or an empty string if no failures found.
*/
public function validation_failures_table() {
$html = '';
if ($this->failuresdata) {
$htmltable = new html_table();
$htmltable->attributes['class'] = 'coderunner-test-results';
$htmltable->head = [
get_string('testcolhdr', 'qtype_coderunner'),
get_string('expectedcolhdr', 'qtype_coderunner'),
get_string('gotcolhdr', 'qtype_coderunner'),
];
$htmltable->data = $this->failuresdata;
$htmltable->rowclasses = $this->failuresrowclasses;
$html = html_writer::table($htmltable) . get_string('replaceexpectedwithgot', 'qtype_coderunner');
}
return $html;
}

/**
*
* @global type $COURSE
Expand Down

0 comments on commit c6e559a

Please sign in to comment.