MDL-77626 quiz statistics: Divide by zero if a random Q has max mark 0

This commit is contained in:
Tim Hunt
2023-03-14 16:29:59 +00:00
parent 0fae900b58
commit 88cedd9f99
2 changed files with 12 additions and 2 deletions
@@ -23,8 +23,11 @@
*/
namespace core_question\statistics\questions;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/question/engine/lib.php');
/**
* Class calculated_question_summary
*
@@ -114,7 +117,7 @@ class calculated_question_summary extends calculated {
$set = false;
foreach ($this->subqstats as $subqstat) {
if (isset($subqstat->sd) && $subqstat->maxmark) {
if (isset($subqstat->sd) && $subqstat->maxmark > \question_utils::MARK_TOLERANCE) {
$value = $subqstat->sd / $subqstat->maxmark;
} else {
$value = null;
@@ -127,7 +127,7 @@ class calculated_question_summary_test extends \advanced_testcase {
],
'zero mark' => [
[
(object)['questionid' => 1, 'sd' => 0.2, 'maxmark' => 0],
(object)['questionid' => 1, 'sd' => 0, 'maxmark' => 0],
(object)['questionid' => 2, 'sd' => 0.1049, 'maxmark' => 1],
],
[null, 0.1049]
@@ -139,6 +139,13 @@ class calculated_question_summary_test extends \advanced_testcase {
],
[0.35, 0.4]
],
'zero max mark as loaded from the DB' => [
[
(object)['questionid' => 1, 'sd' => '0.0000000000', 'maxmark' => '0.0000000'],
(object)['questionid' => 2, 'sd' => '0.0000000000', 'maxmark' => '0.0000000'],
],
[null, null]
],
];
}