Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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', 'pi3tries');
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
    /**
75
     * Get the form data that corresponds to saving a numerical question.
76
     *
77
     * This question asks for Pi to two decimal places. It has feedback
78
     * for various wrong responses. There is hint data there, but
79
     * it is all blank, so no hints are created if this question is saved.
80
     *
81
     * @return stdClass simulated question form data.
82
     */
83
    public function get_numerical_question_form_data_pi() {
84
        $form = new stdClass();
85
        $form->name = 'Pi to two d.p.';
86
        $form->questiontext = array();
87
        $form->questiontext['format'] = '1';
88
        $form->questiontext['text'] = 'What is pi to two d.p.?';
89
 
90
        $form->defaultmark = 1;
91
        $form->generalfeedback = array();
92
        $form->generalfeedback['format'] = '1';
93
        $form->generalfeedback['text'] = 'Generalfeedback: 3.14 is the right answer.';
94
 
95
        $form->noanswers = 6;
96
        $form->answer = array();
97
        $form->answer[0] = '3.14';
98
        $form->answer[1] = '3.142';
99
        $form->answer[2] = '3.1';
100
        $form->answer[3] = '3';
101
        $form->answer[4] = '*';
102
        $form->answer[5] = '';
103
 
104
        $form->tolerance = array();
105
        $form->tolerance[0] = 0;
106
        $form->tolerance[1] = 0;
107
        $form->tolerance[2] = 0;
108
        $form->tolerance[3] = 0;
109
        $form->tolerance[4] = 0;
110
        $form->tolerance[5] = 0;
111
 
112
        $form->fraction = array();
113
        $form->fraction[0] = '1.0';
114
        $form->fraction[1] = '0.0';
115
        $form->fraction[2] = '0.0';
116
        $form->fraction[3] = '0.0';
117
        $form->fraction[4] = '0.0';
118
        $form->fraction[5] = '0.0';
119
 
120
        $form->feedback = array();
121
        $form->feedback[0] = array();
122
        $form->feedback[0]['format'] = '1';
123
        $form->feedback[0]['text'] = 'Very good.';
124
 
125
        $form->feedback[1] = array();
126
        $form->feedback[1]['format'] = '1';
127
        $form->feedback[1]['text'] = 'Too accurate.';
128
 
129
        $form->feedback[2] = array();
130
        $form->feedback[2]['format'] = '1';
131
        $form->feedback[2]['text'] = 'Not accurate enough.';
132
 
133
        $form->feedback[3] = array();
134
        $form->feedback[3]['format'] = '1';
135
        $form->feedback[3]['text'] = 'Not accurate enough.';
136
 
137
        $form->feedback[4] = array();
138
        $form->feedback[4]['format'] = '1';
139
        $form->feedback[4]['text'] = 'Completely wrong.';
140
 
141
        $form->feedback[5] = array();
142
        $form->feedback[5]['format'] = '1';
143
        $form->feedback[5]['text'] = '';
144
 
145
        $form->unitrole = '3';
146
        $form->unitpenalty = 0.1;
147
        $form->unitgradingtypes = '1';
148
        $form->unitsleft = '0';
149
        $form->nounits = 1;
150
        $form->multiplier = array();
151
        $form->multiplier[0] = '1.0';
152
 
153
        $form->penalty = '0.3333333';
154
        $form->numhints = 2;
155
        $form->hint = array();
156
        $form->hint[0] = array();
157
        $form->hint[0]['format'] = '1';
158
        $form->hint[0]['text'] = '';
159
 
160
        $form->hint[1] = array();
161
        $form->hint[1]['format'] = '1';
162
        $form->hint[1]['text'] = '';
163
 
164
        $form->qtype = 'numerical';
165
        $form->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
166
 
1441 ariadna 167
        $form->hint = [
168
            [
169
                'text' => 'Just over 3',
170
                'format' => FORMAT_HTML,
171
            ],
172
        ];
173
 
1 efrain 174
        return $form;
175
    }
176
 
177
    /**
178
     * Get the form data that corresponds to saving a numerical question.
179
     *
180
     * Like {@link get_numerical_question_form_data_pi()}, but
181
     * this time with two hints, making this suitable for use
182
     * with the Interactive with multiple tries behaviour.
183
     *
184
     * @return stdClass simulated question form data.
185
     */
186
    public function get_numerical_question_form_data_pi3tries() {
187
        $form = $this->get_numerical_question_form_data_pi();
1441 ariadna 188
        $form->hint = [
189
            [
190
                'text' => 'First hint',
191
                'format' => FORMAT_HTML,
192
            ],
193
            [
194
                'text' => 'Second hint',
195
                'format' => FORMAT_HTML,
196
            ],
197
        ];
1 efrain 198
        return $form;
199
    }
200
 
201
    public function get_numerical_question_data_pi() {
202
        $q = new stdClass();
203
        $q->name = 'Pi to two d.p.';
204
        $q->questiontext = 'What is pi to two d.p.?';
205
        $q->questiontextformat = FORMAT_HTML;
206
        $q->generalfeedback = 'Generalfeedback: 3.14 is the right answer.';
207
        $q->generalfeedbackformat = FORMAT_HTML;
208
        $q->defaultmark = 1;
209
        $q->penalty = 0.3333333;
210
        $q->qtype = 'numerical';
211
        $q->length = '1';
212
        $q->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
213
        $q->version = 1;
214
        $q->createdby = '2';
215
        $q->modifiedby = '2';
216
        $q->options = new stdClass();
217
        $q->options->answers = array();
218
        $q->options->answers[0] = new stdClass();
219
        $q->options->answers[0]->answer = '3.14';
220
        $q->options->answers[0]->fraction = 1.0;
221
        $q->options->answers[0]->feedback = 'Very good.';
222
        $q->options->answers[0]->feedbackformat = FORMAT_HTML;
223
        $q->options->answers[0]->tolerance = '0';
224
 
225
        $q->options->answers[1] = new stdClass();
226
        $q->options->answers[1]->answer = '3.142';
227
        $q->options->answers[1]->fraction = 0.0;
228
        $q->options->answers[1]->feedback = 'Too accurate.';
229
        $q->options->answers[1]->feedbackformat = FORMAT_HTML;
230
        $q->options->answers[1]->tolerance = '0';
231
 
232
        $q->options->answers[2] = new stdClass();
233
        $q->options->answers[2]->answer = '3.1';
234
        $q->options->answers[2]->fraction = 0.0;
235
        $q->options->answers[2]->feedback = 'Not accurate enough.';
236
        $q->options->answers[2]->feedbackformat = FORMAT_HTML;
237
        $q->options->answers[2]->tolerance = '0';
238
 
239
        $q->options->answers[3] = new stdClass();
240
        $q->options->answers[3]->answer = '3';
241
        $q->options->answers[3]->answerformat = '0';
242
        $q->options->answers[3]->fraction = 0.0;
243
        $q->options->answers[3]->feedback = 'Not accurate enough.';
244
        $q->options->answers[3]->feedbackformat = FORMAT_HTML;
245
        $q->options->answers[3]->tolerance = '0';
246
 
247
        $q->options->answers[4] = new stdClass();
248
        $q->options->answers[4]->answer = '*';
249
        $q->options->answers[4]->answerformat = '0';
250
        $q->options->answers[4]->fraction = 0.0;
251
        $q->options->answers[4]->feedback = 'Completely wrong.';
252
        $q->options->answers[4]->feedbackformat = FORMAT_HTML;
253
        $q->options->answers[4]->tolerance = '0';
254
 
255
        $q->options->units = array();
256
 
257
        $q->options->unitgradingtype = '0';
258
        $q->options->unitpenalty = 0.1;
259
        $q->options->showunits = '3';
260
        $q->options->unitsleft = '0';
261
 
262
        return $q;
263
    }
264
 
265
        /**
266
     * Makes a numerical question with a choice (select menu) of units.
267
     * @return qtype_numerical_question
268
     */
269
    public function make_numerical_question_unit() {
270
        question_bank::load_question_definition_classes('numerical');
271
        $num = new qtype_numerical_question();
272
        test_question_maker::initialise_a_question($num);
273
        $num->name = 'Numerical with units';
274
        $num->questiontext = 'What is 1 m + 25 cm?';
275
        $num->generalfeedback = 'Generalfeedback: 1.25m or 125cm is the right answer.';
276
        $num->answers = array(
277
            13 => new qtype_numerical_answer(13, '1.25', 1.0, 'Very good.', FORMAT_HTML, 0),
278
            14 => new qtype_numerical_answer(14, '1.25', 0.5, 'Vaguely right.', FORMAT_HTML, 0.05),
279
            17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0),
280
        );
281
        $num->qtype = question_bank::get_qtype('numerical');
282
        $num->unitdisplay = qtype_numerical::UNITSELECT;
283
        $num->unitgradingtype = qtype_numerical::UNITGRADEDOUTOFMARK;
284
        $num->unitpenalty = 0.5;
285
        $num->ap = new qtype_numerical_answer_processor(array('m' => 1, 'cm' => 100));
286
 
287
        return $num;
288
    }
289
 
290
    /**
291
     * Makes a numerical question with correct ansewer 3.14, and various incorrect
292
     * answers with different feedback.
293
     * @return qtype_numerical_question
294
     */
295
    public function make_numerical_question_currency() {
296
        question_bank::load_question_definition_classes('numerical');
297
        $num = new qtype_numerical_question();
298
        test_question_maker::initialise_a_question($num);
299
        $num->name = 'Add money';
300
        $num->questiontext = 'What is $666 + $666?';
301
        $num->generalfeedback = 'Generalfeedback: $1,332 is the right answer.';
302
        $num->answers = array(
303
            13 => new qtype_numerical_answer(13, '1332', 1.0, 'Very good.', FORMAT_HTML, 0),
304
            14 => new qtype_numerical_answer(14, '*', 0.0, 'Wrong.', FORMAT_HTML, 0),
305
        );
306
        $num->qtype = question_bank::get_qtype('numerical');
307
        $num->unitdisplay = qtype_numerical::UNITINPUT;
308
        $num->unitgradingtype = qtype_numerical::UNITGRADEDOUTOFMAX;
309
        $num->unitpenalty = 0.2;
310
        $num->ap = new qtype_numerical_answer_processor(array('$' => 1), true);
311
 
312
        return $num;
313
    }
314
}