Skip to content
Snippets Groups Projects
Commit da7ff355 authored by Matti Harjula's avatar Matti Harjula
Browse files

Modify tests and logic to use the new function based accessing of the PRT...

Modify tests and logic to use the new function based accessing of the PRT results, direct field access not currently an option. The on demand unpacking of the values could be done for field access but this is again one of those cases where changign syntax eases in detection of the bits of logic using the old one.
parent 8f96351a
No related branches found
No related tags found
No related merge requests found
......@@ -1338,21 +1338,18 @@ class qtype_stack_question extends question_graded_automatically_with_countback
continue;
}
$prtinput = $this->get_prt_input($index, $response, true);
$results = $this->prts[$index]->evaluate_response($this->session,
$this->options, $prtinput, $this->seed);
$results = $this->get_prt_result($index, $response, true);
$answernotes = implode(' | ', $results->answernotes);
$answernotes = implode(' | ', $results->get_answernotes());
foreach ($prt->get_nodes_summary() as $nodeid => $choices) {
if (in_array($choices->truenote, $results->answernotes)) {
if (in_array($choices->truenote, $results->get_answernotes())) {
$classification[$index . '-' . $nodeid] = new question_classified_response(
$choices->truenote, $answernotes, $results->fraction);
$choices->truenote, $answernotes, $results->get_fraction());
} else if (in_array($choices->falsenote, $results->answernotes)) {
} else if (in_array($choices->falsenote, $results->get_answernotes())) {
$classification[$index . '-' . $nodeid] = new question_classified_response(
$choices->falsenote, $answernotes, $results->fraction);
$choices->falsenote, $answernotes, $results->get_fraction());
} else {
$classification[$index . '-' . $nodeid] = question_classified_response::no_response();
......
......@@ -464,11 +464,11 @@ class qtype_stack_renderer extends qtype_renderer {
}
$result = $question->get_prt_result($name, $relevantresponse, $qa->get_state()->is_finished());
if (is_null($result->valid)) {
if (is_null($result->get_valid())) {
continue;
}
$fraction += $result->fraction;
$fraction += $result->get_fraction();
}
if (is_null($fraction)) {
......
......@@ -183,6 +183,24 @@ class stack_potentialresponse_tree_lite {
return null;
}
// Summary of the nodes, for use in various logics that track answernotes and scores.
public function get_nodes_summary(): array {
$summary = [];
foreach ($this->nodes as $node) {
$n = new stdClass();
$n->truenextnode = $node->truenextnode;
$n->truenote = $node->trueanswernote;
$n->truescore = $node->truescore;
$n->truescoremode = $node->truescoremode;
$n->falsenextnode = $node->falsenextnode;
$n->falsenote = $node->falseanswernote;
$n->falsescore = $node->falsescore;
$n->falsescoremode = $node->falsescoremode;
$summary[$node->nodename] = $n;
}
return $summary;
}
private function po_recurse($node, array &$postorder, array &$visited): array {
$truenode = $this->get_node($node->truenextnode);
$falsenode = $this->get_node($node->falsenextnode);
......
......@@ -243,25 +243,25 @@ abstract class qtype_stack_walkthrough_test_base extends qbehaviour_walkthrough_
$result = $question->get_prt_result($index, $qa, $finalsubmit);
if (is_null($score)) {
$this->assertNull($result->score);
$this->assertNull($result->get_score());
} else {
if ($score == 0) {
// PHP will think a null and are equal, so explicity check not null.
$this->assertNotNull($result->score);
$this->assertNotNull($result->get_score());
}
$this->assertEquals($score, $result->score, 'Wrong score. The PRT returned ' .
$result->score . ' but we expected ' . $score . '.');
$this->assertEquals($score, $result->get_score(), 'Wrong score. The PRT returned ' .
$result->get_score() . ' but we expected ' . $score . '.');
}
if (is_null($penalty)) {
$this->assertNull($result->penalty);
$this->assertNull($result->get_penalty());
} else {
if ($penalty == 0) {
// PHP will think a null and are equal, so explicity check not null.
$this->assertNotNull($result->penalty);
$this->assertNotNull($result->get_penalty());
}
$this->assertEquals($penalty, $result->penalty, 'Wrong penalty. The PRT returned ' .
$result->penalty . ' but we expected ' . $penalty . '.');
$this->assertEquals($penalty, $result->get_penalty(), 'Wrong penalty. The PRT returned ' .
$result->get_penalty() . ' but we expected ' . $penalty . '.');
}
}
......@@ -271,7 +271,7 @@ abstract class qtype_stack_walkthrough_test_base extends qbehaviour_walkthrough_
$qa = $attempt->get_last_qt_data();
$result = $question->get_prt_result($index, $qa, false);
$this->assertEquals($note, implode(' | ', $result->__get('answernotes')));
$this->assertEquals($note, implode(' | ', $result->get_answernotes()));
}
protected function check_response_summary($note) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment