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 calculated question type.
19
 *
20
 * @package    qtype
21
 * @subpackage calculatedmulti
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
global $CFG;
30
require_once($CFG->dirroot . '/question/type/calculatedmulti/question.php');
31
require_once($CFG->dirroot . '/question/type/calculated/tests/helper.php');
32
 
33
/**
34
 * Test helper class for the calculated multiple-choice question type.
35
 *
36
 * @copyright  2011 The Open University
37
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
39
class qtype_calculatedmulti_test_helper extends question_test_helper {
40
    public function get_test_questions() {
41
        return array('singleresponse', 'multiresponse');
42
    }
43
 
44
    /**
45
     * Makes a calculated multiple-choice question about summing two numbers.
46
     * @return qtype_calculatedmulti_single_question
47
     */
48
    public function make_calculatedmulti_question_singleresponse() {
49
        question_bank::load_question_definition_classes('calculated');
50
        $q = new qtype_calculatedmulti_single_question();
51
        test_question_maker::initialise_a_question($q);
52
        $q->name = 'Simple sum';
53
        $q->questiontext = 'What is {a} + {b}?';
54
        $q->generalfeedback = 'Generalfeedback: {={a} + {b}} is the right answer.';
55
        $q->shuffleanswers = 0;
56
        $q->answernumbering = 'abc';
57
        $q->layout = 1;
58
        $q->correctfeedback = test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK;
59
        $q->correctfeedbackformat = FORMAT_HTML;
60
        $q->partiallycorrectfeedback = test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK;
61
        $q->partiallycorrectfeedbackformat = FORMAT_HTML;
62
        $q->shownumcorrect = 1;
63
        $q->incorrectfeedback = test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK;
64
        $q->incorrectfeedbackformat = FORMAT_HTML;
65
        $q->shownumcorrect = 1;
66
        $q->answers = array(
67
            13 => new \qtype_calculated\qtype_calculated_answer(13, '{={a} + {b}}', 1.0, 'Very good.', FORMAT_HTML, 0),
68
            14 => new \qtype_calculated\qtype_calculated_answer(14, '{={a} - {b}}', 0.0, 'Add. not subtract!', FORMAT_HTML, 0),
69
            17 => new \qtype_calculated\qtype_calculated_answer(17, '{={a} + 2 * {b}}', 0.0, 'Just add.', FORMAT_HTML, 0),
70
        );
71
        $q->answers[13]->correctanswerlength = 2;
72
        $q->answers[13]->correctanswerformat = 1;
73
        $q->answers[14]->correctanswerlength = 2;
74
        $q->answers[14]->correctanswerformat = 1;
75
        $q->answers[17]->correctanswerlength = 2;
76
        $q->answers[17]->correctanswerformat = 1;
77
        $q->qtype = question_bank::get_qtype('calculatedmulti');
78
 
79
        $q->datasetloader = new qtype_calculated_test_dataset_loader(0, array(
80
            array('a' => 1, 'b' => 5),
81
            array('a' => 3, 'b' => 4),
82
        ));
83
 
84
        return $q;
85
    }
86
 
87
    /**
88
     * Makes a calculated multiple-choice question with multiple right answers.
89
     * @return qtype_calculatedmulti_multi_question
90
     */
91
    public function make_calculatedmulti_question_multiresponse() {
92
        question_bank::load_question_definition_classes('calculated');
93
        $q = new qtype_calculatedmulti_multi_question();
94
        test_question_maker::initialise_a_question($q);
95
        $q->name = 'Simple sum';
96
        $q->questiontext = 'What is {a} + {b}?';
97
        $q->generalfeedback = 'Generalfeedback: {={a} + {b}} is the right answer.';
98
        $q->shuffleanswers = 0;
99
        $q->answernumbering = 'abc';
100
        $q->layout = 1;
101
        $q->correctfeedback = test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK;
102
        $q->correctfeedbackformat = FORMAT_HTML;
103
        $q->partiallycorrectfeedback = test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK;
104
        $q->partiallycorrectfeedbackformat = FORMAT_HTML;
105
        $q->shownumcorrect = 1;
106
        $q->incorrectfeedback = test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK;
107
        $q->incorrectfeedbackformat = FORMAT_HTML;
108
        $q->shownumcorrect = 1;
109
        $q->answers = array(
110
                13 => new \qtype_calculated\qtype_calculated_answer(13, '{a} + {b}!', 0.5, 'Good', FORMAT_HTML, 0),
111
                14 => new \qtype_calculated\qtype_calculated_answer(14, '{={a} + {b}}', 0.5, 'Good',
112
                        FORMAT_HTML, 0),
113
                17 => new \qtype_calculated\qtype_calculated_answer(17, '{={a} - {b}}', -0.5, 'Wrong.', FORMAT_HTML, 0),
114
        );
115
        $q->answers[13]->correctanswerlength = 2;
116
        $q->answers[13]->correctanswerformat = 1;
117
        $q->answers[14]->correctanswerlength = 2;
118
        $q->answers[14]->correctanswerformat = 1;
119
        $q->answers[17]->correctanswerlength = 2;
120
        $q->answers[17]->correctanswerformat = 1;
121
        $q->qtype = question_bank::get_qtype('calculatedmulti');
122
 
123
        $q->datasetloader = new qtype_calculated_test_dataset_loader(0, array(
124
                array('a' => 1, 'b' => 5),
125
                array('a' => 3, 'b' => 4),
126
        ));
127
 
128
        return $q;
129
    }
1441 ariadna 130
 
131
    /**
132
     * Return the form data for a question with a single response.
133
     *
134
     * @return stdClass
135
     */
136
    public function get_calculatedmulti_question_form_data_singleresponse(): stdClass {
137
        question_bank::load_question_definition_classes('calculated');
138
        $fromform = new stdClass();
139
 
140
        $fromform->name = 'Simple sum';
141
        $fromform->questiontext['text'] = 'What is {a} + {b}?';
142
        $fromform->questiontext['format'] = FORMAT_HTML;
143
        $fromform->defaultmark = 1.0;
144
        $fromform->generalfeedback['text'] = 'Generalfeedback: {={a} + {b}} is the right answer.';
145
        $fromform->generalfeedback['format'] = FORMAT_HTML;
146
 
147
        $fromform->unitrole = '3';
148
        $fromform->unitpenalty = 0.1;
149
        $fromform->unitgradingtypes = '1';
150
        $fromform->unitsleft = '0';
151
        $fromform->nounits = 1;
152
        $fromform->multiplier = [];
153
        $fromform->multiplier[0] = '1.0';
154
        $fromform->synchronize = 0;
155
        $fromform->answernumbering = 0;
156
        $fromform->shuffleanswers = 0;
157
        $fromform->single = 1;
158
        $fromform->correctfeedback['text'] = 'Very good';
159
        $fromform->correctfeedback['format'] = FORMAT_HTML;
160
        $fromform->partiallycorrectfeedback['text'] = 'Mostly good';
161
        $fromform->partiallycorrectfeedback['format'] = FORMAT_HTML;
162
        $fromform->incorrectfeedback['text'] = 'Completely Wrong';
163
        $fromform->incorrectfeedback['format'] = FORMAT_HTML;
164
        $fromform->shownumcorrect = 1;
165
 
166
        $fromform->noanswers = 6;
167
        $fromform->answer = [];
168
        $fromform->answer[0]['text'] = '{a} + {b}';
169
        $fromform->answer[0]['format'] = FORMAT_HTML;
170
        $fromform->answer[1]['text'] = '{a} - {b}';
171
        $fromform->answer[1]['format'] = FORMAT_HTML;
172
        $fromform->answer[2]['text'] = '*';
173
        $fromform->answer[2]['format'] = FORMAT_HTML;
174
 
175
        $fromform->fraction = [];
176
        $fromform->fraction[0] = '1.0';
177
        $fromform->fraction[1] = '0.0';
178
        $fromform->fraction[2] = '0.0';
179
 
180
        $fromform->tolerance = [];
181
        $fromform->tolerance[0] = 0.001;
182
        $fromform->tolerance[1] = 0.001;
183
        $fromform->tolerance[2] = 0;
184
 
185
        $fromform->tolerancetype[0] = 1;
186
        $fromform->tolerancetype[1] = 1;
187
        $fromform->tolerancetype[2] = 1;
188
 
189
        $fromform->correctanswerlength[0] = 2;
190
        $fromform->correctanswerlength[1] = 2;
191
        $fromform->correctanswerlength[2] = 2;
192
 
193
        $fromform->correctanswerformat[0] = 1;
194
        $fromform->correctanswerformat[1] = 1;
195
        $fromform->correctanswerformat[2] = 1;
196
 
197
        $fromform->feedback = [];
198
        $fromform->feedback[0] = [];
199
        $fromform->feedback[0]['format'] = FORMAT_HTML;
200
        $fromform->feedback[0]['text'] = 'Very good.';
201
 
202
        $fromform->feedback[1] = [];
203
        $fromform->feedback[1]['format'] = FORMAT_HTML;
204
        $fromform->feedback[1]['text'] = 'Add. not subtract!';
205
 
206
        $fromform->feedback[2] = [];
207
        $fromform->feedback[2]['format'] = FORMAT_HTML;
208
        $fromform->feedback[2]['text'] = 'Completely wrong.';
209
 
210
        $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
211
 
212
        $fromform->hint = [
213
            [
214
                'text' => 'Add',
215
                'format' => FORMAT_HTML,
216
            ],
217
        ];
218
 
219
        return $fromform;
220
    }
1 efrain 221
}