Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 24... Línea 24...
24
 
24
 
25
global $CFG;
25
global $CFG;
26
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
26
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
Línea 27... Línea -...
27
require_once($CFG->dirroot . '/question/type/ddimageortext/tests/helper.php');
-
 
28
 
27
require_once($CFG->dirroot . '/question/type/ddimageortext/tests/helper.php');
29
 
28
 
30
/**
29
/**
31
 * Unit tests for the matching question definition class.
30
 * Unit tests for the matching question definition class.
32
 *
31
 *
33
 * @package   qtype_ddimageortext
32
 * @package   qtype_ddimageortext
34
 * @copyright 2009 The Open University
33
 * @copyright 2009 The Open University
35
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 * @covers qtype_ddimageortext_question
35
 * @covers qtype_ddimageortext_question
Línea 37... Línea 36...
37
 */
36
 */
38
class question_test extends \basic_testcase {
37
final class question_test extends \basic_testcase {
39
 
38
 
40
    public function test_get_question_summary() {
39
    public function test_get_question_summary(): void {
41
        $dd = \test_question_maker::make_question('ddimageortext');
40
        $dd = \test_question_maker::make_question('ddimageortext');
42
        $this->assertEquals('The quick brown fox jumped over the lazy dog.; '.
41
        $this->assertEquals('The quick brown fox jumped over the lazy dog.; '.
43
                '[[Drop zone 1]] -> {1. quick / 2. fox}; '.
42
                '[[Drop zone 1]] -> {1. quick / 2. fox}; '.
44
                '[[Drop zone 2]] -> {1. quick / 2. fox}; '.
43
                '[[Drop zone 2]] -> {1. quick / 2. fox}; '.
45
                '[[Drop zone 3]] -> {3. lazy / 4. dog}; '.
44
                '[[Drop zone 3]] -> {3. lazy / 4. dog}; '.
Línea 46... Línea 45...
46
                '[[Drop zone 4]] -> {3. lazy / 4. dog}',
45
                '[[Drop zone 4]] -> {3. lazy / 4. dog}',
47
            $dd->get_question_summary());
46
            $dd->get_question_summary());
48
    }
47
    }
49
 
48
 
50
    public function test_get_question_summary_maths() {
49
    public function test_get_question_summary_maths(): void {
51
        $dd = \test_question_maker::make_question('ddimageortext', 'maths');
50
        $dd = \test_question_maker::make_question('ddimageortext', 'maths');
52
        $this->assertEquals('Fill in the operators to make this equation work: '.
51
        $this->assertEquals('Fill in the operators to make this equation work: '.
53
                '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3; '.
52
                '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3; '.
54
                '[[Drop zone 1]] -> {1. + / 2. -}; '.
53
                '[[Drop zone 1]] -> {1. + / 2. -}; '.
55
                '[[Drop zone 2]] -> {1. + / 2. -}; '.
54
                '[[Drop zone 2]] -> {1. + / 2. -}; '.
Línea 56... Línea 55...
56
                '[[Drop zone 3]] -> {1. + / 2. -}; '.
55
                '[[Drop zone 3]] -> {1. + / 2. -}; '.
57
                '[[Drop zone 4]] -> {1. + / 2. -}',
56
                '[[Drop zone 4]] -> {1. + / 2. -}',
58
            $dd->get_question_summary());
57
            $dd->get_question_summary());
59
    }
58
    }
Línea 60... Línea 59...
60
 
59
 
Línea 68... Línea 67...
68
                'Drop zone 3 -> {3. lazy} '.
67
                'Drop zone 3 -> {3. lazy} '.
69
                'Drop zone 4 -> {3. lazy}',
68
                'Drop zone 4 -> {3. lazy}',
70
            $dd->summarise_response(array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
69
            $dd->summarise_response(array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
71
    }
70
    }
Línea 72... Línea 71...
72
 
71
 
73
    public function test_summarise_response_maths() {
72
    public function test_summarise_response_maths(): void {
74
        $dd = \test_question_maker::make_question('ddimageortext', 'maths');
73
        $dd = \test_question_maker::make_question('ddimageortext', 'maths');
75
        $dd->shufflechoices = false;
74
        $dd->shufflechoices = false;
Línea 76... Línea 75...
76
        $dd->start_attempt(new question_attempt_step(), 1);
75
        $dd->start_attempt(new question_attempt_step(), 1);
Línea 80... Línea 79...
80
                'Drop zone 3 -> {1. +} '.
79
                'Drop zone 3 -> {1. +} '.
81
                'Drop zone 4 -> {2. -}',
80
                'Drop zone 4 -> {2. -}',
82
            $dd->summarise_response(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
81
            $dd->summarise_response(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
83
    }
82
    }
Línea 84... Línea 83...
84
 
83
 
85
    public function test_get_random_guess_score() {
84
    public function test_get_random_guess_score(): void {
86
        $dd = \test_question_maker::make_question('ddimageortext');
85
        $dd = \test_question_maker::make_question('ddimageortext');
87
        $this->assertEquals(0.5, $dd->get_random_guess_score());
86
        $this->assertEquals(0.5, $dd->get_random_guess_score());
Línea 88... Línea 87...
88
    }
87
    }
89
 
88
 
90
    public function test_get_random_guess_score_maths() {
89
    public function test_get_random_guess_score_maths(): void {
91
        $dd = \test_question_maker::make_question('ddimageortext', 'maths');
90
        $dd = \test_question_maker::make_question('ddimageortext', 'maths');
Línea 92... Línea 91...
92
        $this->assertEquals(0.5, $dd->get_random_guess_score());
91
        $this->assertEquals(0.5, $dd->get_random_guess_score());
93
    }
92
    }
94
 
93
 
95
    public function test_get_random_guess_score_broken_question() {
94
    public function test_get_random_guess_score_broken_question(): void {
96
        // Before MDL-76298 was fixed, it was possible to create a question with
95
        // Before MDL-76298 was fixed, it was possible to create a question with
97
        // no drop zones, and that caused a fatal division by zero error. Because
96
        // no drop zones, and that caused a fatal division by zero error. Because
98
        // people might have questions like that in their database, we need to
97
        // people might have questions like that in their database, we need to
99
        // check the calculation is robust to it.
98
        // check the calculation is robust to it.
100
        /** @var \qtype_ddimageortext_question $dd */
99
        /** @var \qtype_ddimageortext_question $dd */
101
        $dd = \test_question_maker::make_question('ddimageortext');
100
        $dd = \test_question_maker::make_question('ddimageortext');
Línea 102... Línea 101...
102
        $dd->places = [];
101
        $dd->places = [];
103
        $this->assertNull($dd->get_random_guess_score());
102
        $this->assertNull($dd->get_random_guess_score());
104
    }
103
    }
105
 
104
 
Línea 106... Línea 105...
106
    public function test_get_right_choice_for() {
105
    public function test_get_right_choice_for(): void {
107
        $dd = \test_question_maker::make_question('ddimageortext');
106
        $dd = \test_question_maker::make_question('ddimageortext');
108
        $dd->shufflechoices = false;
107
        $dd->shufflechoices = false;
Línea 109... Línea 108...
109
        $dd->start_attempt(new question_attempt_step(), 1);
108
        $dd->start_attempt(new question_attempt_step(), 1);
110
 
109
 
111
        $this->assertEquals(1, $dd->get_right_choice_for(1));
110
        $this->assertEquals(1, $dd->get_right_choice_for(1));
112
        $this->assertEquals(2, $dd->get_right_choice_for(2));
111
        $this->assertEquals(2, $dd->get_right_choice_for(2));
Línea 113... Línea 112...
113
    }
112
    }
114
 
113
 
115
    public function test_get_right_choice_for_maths() {
114
    public function test_get_right_choice_for_maths(): void {
116
        $dd = \test_question_maker::make_question('ddimageortext', 'maths');
115
        $dd = \test_question_maker::make_question('ddimageortext', 'maths');
117
        $dd->shufflechoices = false;
116
        $dd->shufflechoices = false;
Línea 118... Línea 117...
118
        $dd->start_attempt(new question_attempt_step(), 1);
117
        $dd->start_attempt(new question_attempt_step(), 1);
119
 
118
 
120
        $this->assertEquals(1, $dd->get_right_choice_for(1));
119
        $this->assertEquals(1, $dd->get_right_choice_for(1));
121
        $this->assertEquals(2, $dd->get_right_choice_for(2));
120
        $this->assertEquals(2, $dd->get_right_choice_for(2));
Línea 122... Línea 121...
122
        $this->assertEquals(1, $dd->get_right_choice_for(3));
121
        $this->assertEquals(1, $dd->get_right_choice_for(3));
123
        $this->assertEquals(2, $dd->get_right_choice_for(4));
122
        $this->assertEquals(2, $dd->get_right_choice_for(4));
124
    }
123
    }
125
 
124
 
Línea 126... Línea 125...
126
    public function test_clear_wrong_from_response() {
125
    public function test_clear_wrong_from_response(): void {
127
        $dd = \test_question_maker::make_question('ddimageortext', 'maths');
126
        $dd = \test_question_maker::make_question('ddimageortext', 'maths');
128
        $dd->shufflechoices = false;
127
        $dd->shufflechoices = false;
129
        $dd->start_attempt(new question_attempt_step(), 1);
128
        $dd->start_attempt(new question_attempt_step(), 1);
Línea 130... Línea 129...
130
 
129
 
131
        $initialresponse = array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1');
130
        $initialresponse = array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1');
132
        $this->assertEquals(array('p1' => '1', 'p2' => '', 'p3' => '1', 'p4' => ''),
131
        $this->assertEquals(array('p1' => '1', 'p2' => '', 'p3' => '1', 'p4' => ''),
133
            $dd->clear_wrong_from_response($initialresponse));
132
            $dd->clear_wrong_from_response($initialresponse));
134
    }
133
    }
Línea 135... Línea 134...
135
 
134
 
136
    public function test_get_num_parts_right() {
135
    public function test_get_num_parts_right(): void {
137
        $dd = \test_question_maker::make_question('ddimageortext');
136
        $dd = \test_question_maker::make_question('ddimageortext');
138
        $dd->shufflechoices = false;
137
        $dd->shufflechoices = false;
Línea 139... Línea 138...
139
        $dd->start_attempt(new question_attempt_step(), 1);
138
        $dd->start_attempt(new question_attempt_step(), 1);
140
 
139
 
141
        $this->assertEquals(array(2, 4),
140
        $this->assertEquals(array(2, 4),
142
            $dd->get_num_parts_right(array('p1' => '1', 'p2' => '1', 'p3' => '2', 'p4' => '2')));
141
            $dd->get_num_parts_right(array('p1' => '1', 'p2' => '1', 'p3' => '2', 'p4' => '2')));
Línea 143... Línea 142...
143
        $this->assertEquals(array(4, 4),
142
        $this->assertEquals(array(4, 4),
144
            $dd->get_num_parts_right(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
143
            $dd->get_num_parts_right(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
145
    }
144
    }
Línea 146... Línea 145...
146
 
145
 
147
    public function test_get_num_parts_right_maths() {
146
    public function test_get_num_parts_right_maths(): void {
148
        $dd = \test_question_maker::make_question('ddimageortext', 'maths');
147
        $dd = \test_question_maker::make_question('ddimageortext', 'maths');
149
        $dd->shufflechoices = false;
148
        $dd->shufflechoices = false;
150
        $dd->start_attempt(new question_attempt_step(), 1);
149
        $dd->start_attempt(new question_attempt_step(), 1);
Línea 151... Línea 150...
151
 
150
 
152
        $this->assertEquals(array(2, 4),
151
        $this->assertEquals(array(2, 4),
153
            $dd->get_num_parts_right(array(
152
            $dd->get_num_parts_right(array(
154
                'p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
153
                'p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
Línea 155... Línea 154...
155
    }
154
    }
156
 
155
 
157
    public function test_get_expected_data() {
156
    public function test_get_expected_data(): void {
Línea 158... Línea 157...
158
        $dd = \test_question_maker::make_question('ddimageortext');
157
        $dd = \test_question_maker::make_question('ddimageortext');
159
        $dd->start_attempt(new question_attempt_step(), 1);
158
        $dd->start_attempt(new question_attempt_step(), 1);
160
 
159
 
161
        $this->assertEquals(
160
        $this->assertEquals(
Línea 162... Línea 161...
162
            array('p1' => PARAM_INT, 'p2' => PARAM_INT, 'p3' => PARAM_INT, 'p4' => PARAM_INT),
161
            array('p1' => PARAM_INT, 'p2' => PARAM_INT, 'p3' => PARAM_INT, 'p4' => PARAM_INT),
163
            $dd->get_expected_data()
162
            $dd->get_expected_data()
164
        );
163
        );
Línea 165... Línea 164...
165
    }
164
    }
166
 
165
 
167
    public function test_get_correct_response() {
166
    public function test_get_correct_response(): void {
Línea 168... Línea 167...
168
        $dd = \test_question_maker::make_question('ddimageortext');
167
        $dd = \test_question_maker::make_question('ddimageortext');
169
        $dd->shufflechoices = false;
168
        $dd->shufflechoices = false;
Línea 204... Línea 203...
204
 
203
 
205
        $this->assertFalse($dd->is_same_response(
204
        $this->assertFalse($dd->is_same_response(
206
            array('p1' => '1', 'p2' => '2', 'p3' => '3', 'p4' => '4'),
205
            array('p1' => '1', 'p2' => '2', 'p3' => '3', 'p4' => '4'),
207
            array('p1' => '1', 'p2' => '2', 'p3' => '2', 'p4' => '4')));
206
            array('p1' => '1', 'p2' => '2', 'p3' => '2', 'p4' => '4')));
208
    }
207
    }
209
    public function test_is_complete_response() {
208
    public function test_is_complete_response(): void {
210
        $dd = \test_question_maker::make_question('ddimageortext');
209
        $dd = \test_question_maker::make_question('ddimageortext');
Línea 211... Línea 210...
211
        $dd->start_attempt(new question_attempt_step(), 1);
210
        $dd->start_attempt(new question_attempt_step(), 1);
212
 
211
 
Línea 216... Línea 215...
216
        $this->assertFalse($dd->is_complete_response(array('p1' => '1')));
215
        $this->assertFalse($dd->is_complete_response(array('p1' => '1')));
217
        $this->assertTrue($dd->is_complete_response(
216
        $this->assertTrue($dd->is_complete_response(
218
            array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
217
            array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
219
    }
218
    }
Línea 220... Línea 219...
220
 
219
 
221
    public function test_is_gradable_response() {
220
    public function test_is_gradable_response(): void {
222
        $dd = \test_question_maker::make_question('ddimageortext');
221
        $dd = \test_question_maker::make_question('ddimageortext');
Línea 223... Línea 222...
223
        $dd->start_attempt(new question_attempt_step(), 1);
222
        $dd->start_attempt(new question_attempt_step(), 1);
224
 
223
 
225
        $this->assertFalse($dd->is_gradable_response(array()));
224
        $this->assertFalse($dd->is_gradable_response(array()));
226
        $this->assertFalse($dd->is_gradable_response(
225
        $this->assertFalse($dd->is_gradable_response(
227
            array('p1' => '', 'p2' => '', 'p3' => '', 'p3' => '')));
226
            array('p1' => '', 'p2' => '', 'p3' => '')));
228
        $this->assertTrue($dd->is_gradable_response(
227
        $this->assertTrue($dd->is_gradable_response(
229
            array('p1' => '1', 'p2' => '1', 'p3' => '')));
228
            array('p1' => '1', 'p2' => '1', 'p3' => '')));
230
        $this->assertTrue($dd->is_gradable_response(array('p1' => '1')));
229
        $this->assertTrue($dd->is_gradable_response(array('p1' => '1')));
231
        $this->assertTrue($dd->is_gradable_response(
230
        $this->assertTrue($dd->is_gradable_response(
Línea 232... Línea 231...
232
            array('p1' => '1', 'p2' => '1', 'p3' => '1')));
231
            array('p1' => '1', 'p2' => '1', 'p3' => '1')));
233
    }
232
    }
234
 
233
 
235
    public function test_grading() {
234
    public function test_grading(): void {
Línea 236... Línea 235...
236
        $dd = \test_question_maker::make_question('ddimageortext');
235
        $dd = \test_question_maker::make_question('ddimageortext');
Línea 243... Línea 242...
243
            $dd->grade_response(array('p1' => '1')));
242
            $dd->grade_response(array('p1' => '1')));
244
        $this->assertEquals(array(0, question_state::$gradedwrong),
243
        $this->assertEquals(array(0, question_state::$gradedwrong),
245
            $dd->grade_response(array('p1' => '2', 'p2' => '1', 'p3' => '2', 'p4' => '1')));
244
            $dd->grade_response(array('p1' => '2', 'p2' => '1', 'p3' => '2', 'p4' => '1')));
246
    }
245
    }
Línea 247... Línea 246...
247
 
246
 
248
    public function test_grading_maths() {
247
    public function test_grading_maths(): void {
249
        $dd = \test_question_maker::make_question('ddimageortext', 'maths');
248
        $dd = \test_question_maker::make_question('ddimageortext', 'maths');
250
        $dd->shufflechoices = false;
249
        $dd->shufflechoices = false;
Línea 251... Línea 250...
251
        $dd->start_attempt(new question_attempt_step(), 1);
250
        $dd->start_attempt(new question_attempt_step(), 1);
Línea 256... Línea 255...
256
            $dd->grade_response(array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
255
            $dd->grade_response(array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
257
        $this->assertEquals(array(0, question_state::$gradedwrong),
256
        $this->assertEquals(array(0, question_state::$gradedwrong),
258
            $dd->grade_response(array('p1' => '', 'p2' => '1', 'p3' => '2', 'p4' => '1')));
257
            $dd->grade_response(array('p1' => '', 'p2' => '1', 'p3' => '2', 'p4' => '1')));
259
    }
258
    }
Línea 260... Línea 259...
260
 
259
 
261
    public function test_classify_response() {
260
    public function test_classify_response(): void {
262
        $dd = \test_question_maker::make_question('ddimageortext');
261
        $dd = \test_question_maker::make_question('ddimageortext');
263
        $dd->shufflechoices = false;
262
        $dd->shufflechoices = false;
Línea 264... Línea 263...
264
        $dd->start_attempt(new question_attempt_step(), 1);
263
        $dd->start_attempt(new question_attempt_step(), 1);
Línea 275... Línea 274...
275
            3 => new question_classified_response(4, '4. dog', 0),
274
            3 => new question_classified_response(4, '4. dog', 0),
276
            4 => new question_classified_response(4, '4. dog', 1)
275
            4 => new question_classified_response(4, '4. dog', 1)
277
        ), $dd->classify_response(array('p1' => '', 'p2' => '1', 'p3' => '2', 'p4' => '2')));
276
        ), $dd->classify_response(array('p1' => '', 'p2' => '1', 'p3' => '2', 'p4' => '2')));
278
    }
277
    }
Línea 279... Línea 278...
279
 
278
 
280
    public function test_summarise_response_choice_deleted() {
279
    public function test_summarise_response_choice_deleted(): void {
281
        /** @var qtype_ddtoimage_question_base $dd */
280
        /** @var qtype_ddtoimage_question_base $dd */
282
        $dd = \test_question_maker::make_question('ddimageortext');
281
        $dd = \test_question_maker::make_question('ddimageortext');
283
        $dd->shufflechoices = false;
282
        $dd->shufflechoices = false;
284
        $dd->start_attempt(new question_attempt_step(), 1);
283
        $dd->start_attempt(new question_attempt_step(), 1);