Skip to content

Commit

Permalink
Matrix: Add the get_num_correct_choices function #739047
Browse files Browse the repository at this point in the history
  • Loading branch information
mkassaei authored and timhunt committed Nov 15, 2023
1 parent 8352d43 commit c32eede
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,17 @@ public function get_num_selected_choices(array $response): int {
}
return $numselected;
}

/**
* Returns the count of correct answers for the question.
*
* @return int the number of choices that are correct.
*/
public function get_num_correct_choices(): int {
$numcorrect = 0;
foreach ($this->rows as $row) {
$numcorrect += count($row->correctanswers);
}
return $numcorrect;
}
}
7 changes: 7 additions & 0 deletions tests/question_multiple_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,11 @@ public function test_get_num_parts_grade_partial(): void {
// Two responsess are given and both are correct (Second and third row have not been answered).
$this->assertEquals([2, 7], $question->get_num_parts_grade_partial(['rowanswers0_1' => '1', 'rowanswers0_3' => '1']));
}

public function test_get_num_correct_choices(): void {
$question = \test_question_maker::make_question('oumatrix', 'food_multiple');

// Correct number of choices are expected.
$this->assertEquals(7, $question->get_num_correct_choices());
}
}

0 comments on commit c32eede

Please sign in to comment.