Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  namespace core_question;
  18  
  19  use core_question\statistics\questions\calculated_question_summary;
  20  
  21  /**
  22   * Class core_question_calculated_question_summary_testcase
  23   *
  24   * @package    core_question
  25   * @category   test
  26   * @copyright  2018 Shamim Rezaie <shamim@moodle.com>
  27   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28   */
  29  class calculated_question_summary_test extends \advanced_testcase {
  30  
  31      /**
  32       * Provider for test_get_min_max_of.
  33       *
  34       * @return array
  35       */
  36      public function get_min_max_provider() {
  37          return [
  38              'negative number and null' => [
  39                  [
  40                      (object)['questionid' => 1, 'index' => 2],
  41                      (object)['questionid' => 2, 'index' => -7],
  42                      (object)['questionid' => 3, 'index' => null],
  43                      (object)['questionid' => 4, 'index' => 12],
  44                  ],
  45                  [-7, 12]
  46              ],
  47              'null and negative number' => [
  48                  [
  49                      (object)['questionid' => 1, 'index' => 2],
  50                      (object)['questionid' => 2, 'index' => null],
  51                      (object)['questionid' => 3, 'index' => -7],
  52                      (object)['questionid' => 4, 'index' => 12],
  53                  ],
  54                  [-7, 12]
  55              ],
  56              'negative number and null as maximum' => [
  57                  [
  58                      (object)['questionid' => 1, 'index' => -2],
  59                      (object)['questionid' => 2, 'index' => null],
  60                      (object)['questionid' => 3, 'index' => -7],
  61                  ],
  62                  [-7, null]
  63              ],
  64              'zero and null' => [
  65                  [
  66                      (object)['questionid' => 1, 'index' => 2],
  67                      (object)['questionid' => 2, 'index' => 0],
  68                      (object)['questionid' => 3, 'index' => null],
  69                      (object)['questionid' => 4, 'index' => 12],
  70                  ],
  71                  [0, 12]
  72              ],
  73              'null as minimum' => [
  74                  [
  75                      (object)['questionid' => 1, 'index' => 2],
  76                      (object)['questionid' => 2, 'index' => null],
  77                      (object)['questionid' => 3, 'index' => 12],
  78                  ],
  79                  [null, 12]
  80              ],
  81              'null and null' => [
  82                  [
  83                      (object)['questionid' => 1, 'index' => 2],
  84                      (object)['questionid' => 2, 'index' => null],
  85                      (object)['questionid' => 3, 'index' => null],
  86                  ],
  87                  [null, 2]
  88              ],
  89          ];
  90      }
  91  
  92      /**
  93       * Unit test for get_min_max_of() method.
  94       *
  95       * @dataProvider get_min_max_provider
  96       */
  97      public function test_get_min_max_of($subqstats, $expected) {
  98          $calculatedsummary = new calculated_question_summary(null, null, $subqstats);
  99          $res = $calculatedsummary->get_min_max_of('index');
 100          $this->assertEquals($expected, $res);
 101      }
 102  
 103      /**
 104       * Provider for test_get_min_max_of.
 105       *
 106       * @return array
 107       */
 108      public function get_sd_min_max_provider() {
 109          return [
 110              'null and number' => [
 111                  [
 112                      (object)['questionid' => 1, 'sd' => 0.2, 'maxmark' => 0.5],
 113                      (object)['questionid' => 2, 'sd' => null, 'maxmark' => 1],
 114                      (object)['questionid' => 3, 'sd' => 0.1049, 'maxmark' => 1],
 115                      (object)['questionid' => 4, 'sd' => 0.12, 'maxmark' => 1],
 116                  ],
 117                  [null, 0.4]
 118              ],
 119              'null and zero' => [
 120                  [
 121                      (object)['questionid' => 1, 'sd' => 0.2, 'maxmark' => 0.5],
 122                      (object)['questionid' => 2, 'sd' => null, 'maxmark' => 1],
 123                      (object)['questionid' => 3, 'sd' => 0, 'maxmark' => 1],
 124                      (object)['questionid' => 4, 'sd' => 0.12, 'maxmark' => 1],
 125                  ],
 126                  [0, 0.4]
 127              ],
 128              'zero mark' => [
 129                  [
 130                      (object)['questionid' => 1, 'sd' => 0.2, 'maxmark' => 0],
 131                      (object)['questionid' => 2, 'sd' => 0.1049, 'maxmark' => 1],
 132                  ],
 133                  [null, 0.1049]
 134              ],
 135              'nonzero and nonzero' => [
 136                  [
 137                      (object)['questionid' => 1, 'sd' => 0.2, 'maxmark' => 0.5],
 138                      (object)['questionid' => 2, 'sd' => 0.7, 'maxmark' => 2],
 139                  ],
 140                  [0.35, 0.4]
 141              ],
 142          ];
 143      }
 144  
 145      /**
 146       * Unit test for get_min_max_of_sd() method.
 147       *
 148       * @dataProvider get_sd_min_max_provider
 149       */
 150      public function test_get_min_max_of_sd($subqstats, $expected) {
 151          $calculatedsummary = new calculated_question_summary(null, null, $subqstats);
 152          $res = $calculatedsummary->get_min_max_of('sd');
 153          $this->assertEquals($expected, $res);
 154      }
 155  }