diff --git a/question/classes/statistics/questions/calculated_question_summary.php b/question/classes/statistics/questions/calculated_question_summary.php index 982baf347af..bbce6db836d 100644 --- a/question/classes/statistics/questions/calculated_question_summary.php +++ b/question/classes/statistics/questions/calculated_question_summary.php @@ -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; diff --git a/question/tests/calculated_question_summary_test.php b/question/tests/calculated_question_summary_test.php index 5717f1caf7a..b90dcf82366 100644 --- a/question/tests/calculated_question_summary_test.php +++ b/question/tests/calculated_question_summary_test.php @@ -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] + ], ]; }