Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/type/numerical/simpletest/helper.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 
00036 class qtype_numerical_test_helper extends question_test_helper {
00037     public function get_test_questions() {
00038         return array('pi', 'unit', 'currency');
00039     }
00040 
00046     public function make_numerical_question_pi() {
00047         question_bank::load_question_definition_classes('numerical');
00048         $num = new qtype_numerical_question();
00049         test_question_maker::initialise_a_question($num);
00050         $num->name = 'Pi to two d.p.';
00051         $num->questiontext = 'What is pi to two d.p.?';
00052         $num->generalfeedback = 'Generalfeedback: 3.14 is the right answer.';
00053         $num->answers = array(
00054             13 => new qtype_numerical_answer(13, '3.14',  1.0, 'Very good.',
00055                     FORMAT_HTML, 0),
00056             14 => new qtype_numerical_answer(14, '3.142', 0.0, 'Too accurate.',
00057                     FORMAT_HTML, 0.005),
00058             15 => new qtype_numerical_answer(15, '3.1',   0.0, 'Not accurate enough.',
00059                     FORMAT_HTML, 0.05),
00060             16 => new qtype_numerical_answer(16, '3',     0.0, 'Not accurate enough.',
00061                     FORMAT_HTML, 0.5),
00062             17 => new qtype_numerical_answer(17, '*',     0.0, 'Completely wrong.',
00063                     FORMAT_HTML, 0),
00064         );
00065         $num->qtype = question_bank::get_qtype('numerical');
00066         $num->unitdisplay = qtype_numerical::UNITOPTIONAL;
00067         $num->unitgradingtype = 0;
00068         $num->unitpenalty = 0.2;
00069         $num->ap = new qtype_numerical_answer_processor(array());
00070 
00071         return $num;
00072     }
00073 
00078     public function make_numerical_question_unit() {
00079         question_bank::load_question_definition_classes('numerical');
00080         $num = new qtype_numerical_question();
00081         test_question_maker::initialise_a_question($num);
00082         $num->name = 'Numerical with units';
00083         $num->questiontext = 'What is 1 m + 25 cm?';
00084         $num->generalfeedback = 'Generalfeedback: 1.25m or 125cm is the right answer.';
00085         $num->answers = array(
00086             13 => new qtype_numerical_answer(13, '1.25', 1.0, 'Very good.', FORMAT_HTML, 0),
00087             14 => new qtype_numerical_answer(14, '1.25', 0.5, 'Vaguely right.', FORMAT_HTML, 0.05),
00088             17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0),
00089         );
00090         $num->qtype = question_bank::get_qtype('numerical');
00091         $num->unitdisplay = qtype_numerical::UNITSELECT;
00092         $num->unitgradingtype = qtype_numerical::UNITGRADEDOUTOFMARK;
00093         $num->unitpenalty = 0.5;
00094         $num->ap = new qtype_numerical_answer_processor(array('m' => 1, 'cm' => 100));
00095 
00096         return $num;
00097     }
00098 
00104     public function make_numerical_question_currency() {
00105         question_bank::load_question_definition_classes('numerical');
00106         $num = new qtype_numerical_question();
00107         test_question_maker::initialise_a_question($num);
00108         $num->name = 'Add money';
00109         $num->questiontext = 'What is $666 + $666?';
00110         $num->generalfeedback = 'Generalfeedback: $1,332 is the right answer.';
00111         $num->answers = array(
00112             13 => new qtype_numerical_answer(13, '1332', 1.0, 'Very good.', FORMAT_HTML, 0),
00113             14 => new qtype_numerical_answer(14, '*', 0.0, 'Wrong.', FORMAT_HTML, 0),
00114         );
00115         $num->qtype = question_bank::get_qtype('numerical');
00116         $num->unitdisplay = qtype_numerical::UNITINPUT;
00117         $num->unitgradingtype = qtype_numerical::UNITGRADEDOUTOFMAX;
00118         $num->unitpenalty = 0.2;
00119         $num->ap = new qtype_numerical_answer_processor(array('$' => 1), true);
00120 
00121         return $num;
00122     }
00123 }
 All Data Structures Namespaces Files Functions Variables Enumerations