[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 /** 18 * Test helpers for the numerical question type. 19 * 20 * @package qtype 21 * @subpackage numerical 22 * @copyright 2011 The Open University 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 30 /** 31 * Test helper class for the numerical question type. 32 * 33 * @copyright 2011 The Open University 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class qtype_numerical_test_helper extends question_test_helper { 37 public function get_test_questions() { 38 return array('pi', 'unit', 'currency'); 39 } 40 41 /** 42 * Makes a numerical question with correct ansewer 3.14, and various incorrect 43 * answers with different feedback. 44 * @return qtype_numerical_question 45 */ 46 public function make_numerical_question_pi() { 47 question_bank::load_question_definition_classes('numerical'); 48 $num = new qtype_numerical_question(); 49 test_question_maker::initialise_a_question($num); 50 $num->name = 'Pi to two d.p.'; 51 $num->questiontext = 'What is pi to two d.p.?'; 52 $num->generalfeedback = 'Generalfeedback: 3.14 is the right answer.'; 53 $num->answers = array( 54 13 => new qtype_numerical_answer(13, '3.14', 1.0, 'Very good.', 55 FORMAT_HTML, 0), 56 14 => new qtype_numerical_answer(14, '3.142', 0.0, 'Too accurate.', 57 FORMAT_HTML, 0.005), 58 15 => new qtype_numerical_answer(15, '3.1', 0.0, 'Not accurate enough.', 59 FORMAT_HTML, 0.05), 60 16 => new qtype_numerical_answer(16, '3', 0.0, 'Not accurate enough.', 61 FORMAT_HTML, 0.5), 62 17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', 63 FORMAT_HTML, 0), 64 ); 65 $num->qtype = question_bank::get_qtype('numerical'); 66 $num->unitdisplay = qtype_numerical::UNITOPTIONAL; 67 $num->unitgradingtype = 0; 68 $num->unitpenalty = 0.2; 69 $num->ap = new qtype_numerical_answer_processor(array()); 70 71 return $num; 72 } 73 74 public function get_numerical_question_form_data_pi() { 75 $form = new stdClass(); 76 $form->name = 'Pi to two d.p.'; 77 $form->questiontext = array(); 78 $form->questiontext['format'] = '1'; 79 $form->questiontext['text'] = 'What is pi to two d.p.?'; 80 81 $form->defaultmark = 1; 82 $form->generalfeedback = array(); 83 $form->generalfeedback['format'] = '1'; 84 $form->generalfeedback['text'] = 'Generalfeedback: 3.14 is the right answer.'; 85 86 $form->noanswers = 6; 87 $form->answer = array(); 88 $form->answer[0] = '3.14'; 89 $form->answer[1] = '3.142'; 90 $form->answer[2] = '3.1'; 91 $form->answer[3] = '3'; 92 $form->answer[4] = '*'; 93 $form->answer[5] = ''; 94 95 $form->tolerance = array(); 96 $form->tolerance[0] = 0; 97 $form->tolerance[1] = 0; 98 $form->tolerance[2] = 0; 99 $form->tolerance[3] = 0; 100 $form->tolerance[4] = 0; 101 $form->tolerance[5] = 0; 102 103 $form->fraction = array(); 104 $form->fraction[0] = '1.0'; 105 $form->fraction[1] = '0.0'; 106 $form->fraction[2] = '0.0'; 107 $form->fraction[3] = '0.0'; 108 $form->fraction[4] = '0.0'; 109 $form->fraction[5] = '0.0'; 110 111 $form->feedback = array(); 112 $form->feedback[0] = array(); 113 $form->feedback[0]['format'] = '1'; 114 $form->feedback[0]['text'] = 'Very good.'; 115 116 $form->feedback[1] = array(); 117 $form->feedback[1]['format'] = '1'; 118 $form->feedback[1]['text'] = 'Too accurate.'; 119 120 $form->feedback[2] = array(); 121 $form->feedback[2]['format'] = '1'; 122 $form->feedback[2]['text'] = 'Not accurate enough.'; 123 124 $form->feedback[3] = array(); 125 $form->feedback[3]['format'] = '1'; 126 $form->feedback[3]['text'] = 'Not accurate enough.'; 127 128 $form->feedback[4] = array(); 129 $form->feedback[4]['format'] = '1'; 130 $form->feedback[4]['text'] = 'Completely wrong.'; 131 132 $form->feedback[5] = array(); 133 $form->feedback[5]['format'] = '1'; 134 $form->feedback[5]['text'] = ''; 135 136 $form->unitrole = '3'; 137 $form->unitpenalty = 0.1; 138 $form->unitgradingtypes = '1'; 139 $form->unitsleft = '0'; 140 $form->nounits = 1; 141 $form->multiplier = array(); 142 $form->multiplier[0] = '1.0'; 143 144 $form->penalty = '0.3333333'; 145 $form->numhints = 2; 146 $form->hint = array(); 147 $form->hint[0] = array(); 148 $form->hint[0]['format'] = '1'; 149 $form->hint[0]['text'] = ''; 150 151 $form->hint[1] = array(); 152 $form->hint[1]['format'] = '1'; 153 $form->hint[1]['text'] = ''; 154 155 $form->qtype = 'numerical'; 156 return $form; 157 } 158 159 public function get_numerical_question_data_pi() { 160 $q = new stdClass(); 161 $q->name = 'Pi to two d.p.'; 162 $q->questiontext = 'What is pi to two d.p.?'; 163 $q->questiontextformat = FORMAT_HTML; 164 $q->generalfeedback = 'Generalfeedback: 3.14 is the right answer.'; 165 $q->generalfeedbackformat = FORMAT_HTML; 166 $q->defaultmark = 1; 167 $q->penalty = 0.3333333; 168 $q->qtype = 'numerical'; 169 $q->length = '1'; 170 $q->hidden = '0'; 171 $q->createdby = '2'; 172 $q->modifiedby = '2'; 173 $q->options = new stdClass(); 174 $q->options->answers = array(); 175 $q->options->answers[0] = new stdClass(); 176 $q->options->answers[0]->answer = '3.14'; 177 $q->options->answers[0]->fraction = '1.0000000'; 178 $q->options->answers[0]->feedback = 'Very good.'; 179 $q->options->answers[0]->feedbackformat = FORMAT_HTML; 180 $q->options->answers[0]->tolerance = '0'; 181 182 $q->options->answers[1] = new stdClass(); 183 $q->options->answers[1]->answer = '3.142'; 184 $q->options->answers[1]->fraction = '0.0000000'; 185 $q->options->answers[1]->feedback = 'Too accurate.'; 186 $q->options->answers[1]->feedbackformat = FORMAT_HTML; 187 $q->options->answers[1]->tolerance = '0'; 188 189 $q->options->answers[2] = new stdClass(); 190 $q->options->answers[2]->answer = '3.1'; 191 $q->options->answers[2]->fraction = '0.0000000'; 192 $q->options->answers[2]->feedback = 'Not accurate enough.'; 193 $q->options->answers[2]->feedbackformat = FORMAT_HTML; 194 $q->options->answers[2]->tolerance = '0'; 195 196 $q->options->answers[3] = new stdClass(); 197 $q->options->answers[3]->answer = '3'; 198 $q->options->answers[3]->answerformat = '0'; 199 $q->options->answers[3]->fraction = '0.0000000'; 200 $q->options->answers[3]->feedback = 'Not accurate enough.'; 201 $q->options->answers[3]->feedbackformat = FORMAT_HTML; 202 $q->options->answers[3]->tolerance = '0'; 203 204 $q->options->answers[4] = new stdClass(); 205 $q->options->answers[4]->answer = '*'; 206 $q->options->answers[4]->answerformat = '0'; 207 $q->options->answers[4]->fraction = '0.0000000'; 208 $q->options->answers[4]->feedback = 'Completely wrong.'; 209 $q->options->answers[4]->feedbackformat = FORMAT_HTML; 210 $q->options->answers[4]->tolerance = '0'; 211 212 $q->options->units = array(); 213 214 $q->options->unitgradingtype = '0'; 215 $q->options->unitpenalty = '0.1000000'; 216 $q->options->showunits = '3'; 217 $q->options->unitsleft = '0'; 218 219 return $q; 220 } 221 222 /** 223 * Makes a numerical question with a choice (select menu) of units. 224 * @return qtype_numerical_question 225 */ 226 public function make_numerical_question_unit() { 227 question_bank::load_question_definition_classes('numerical'); 228 $num = new qtype_numerical_question(); 229 test_question_maker::initialise_a_question($num); 230 $num->name = 'Numerical with units'; 231 $num->questiontext = 'What is 1 m + 25 cm?'; 232 $num->generalfeedback = 'Generalfeedback: 1.25m or 125cm is the right answer.'; 233 $num->answers = array( 234 13 => new qtype_numerical_answer(13, '1.25', 1.0, 'Very good.', FORMAT_HTML, 0), 235 14 => new qtype_numerical_answer(14, '1.25', 0.5, 'Vaguely right.', FORMAT_HTML, 0.05), 236 17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0), 237 ); 238 $num->qtype = question_bank::get_qtype('numerical'); 239 $num->unitdisplay = qtype_numerical::UNITSELECT; 240 $num->unitgradingtype = qtype_numerical::UNITGRADEDOUTOFMARK; 241 $num->unitpenalty = 0.5; 242 $num->ap = new qtype_numerical_answer_processor(array('m' => 1, 'cm' => 100)); 243 244 return $num; 245 } 246 247 /** 248 * Makes a numerical question with correct ansewer 3.14, and various incorrect 249 * answers with different feedback. 250 * @return qtype_numerical_question 251 */ 252 public function make_numerical_question_currency() { 253 question_bank::load_question_definition_classes('numerical'); 254 $num = new qtype_numerical_question(); 255 test_question_maker::initialise_a_question($num); 256 $num->name = 'Add money'; 257 $num->questiontext = 'What is $666 + $666?'; 258 $num->generalfeedback = 'Generalfeedback: $1,332 is the right answer.'; 259 $num->answers = array( 260 13 => new qtype_numerical_answer(13, '1332', 1.0, 'Very good.', FORMAT_HTML, 0), 261 14 => new qtype_numerical_answer(14, '*', 0.0, 'Wrong.', FORMAT_HTML, 0), 262 ); 263 $num->qtype = question_bank::get_qtype('numerical'); 264 $num->unitdisplay = qtype_numerical::UNITINPUT; 265 $num->unitgradingtype = qtype_numerical::UNITGRADEDOUTOFMAX; 266 $num->unitpenalty = 0.2; 267 $num->ap = new qtype_numerical_answer_processor(array('$' => 1), true); 268 269 return $num; 270 } 271 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |