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 |
namespace qtype_ddwtos;
|
|
|
18 |
|
|
|
19 |
use question_attempt_step;
|
|
|
20 |
use question_classified_response;
|
|
|
21 |
use question_state;
|
|
|
22 |
|
|
|
23 |
defined('MOODLE_INTERNAL') || die();
|
|
|
24 |
global $CFG;
|
|
|
25 |
|
|
|
26 |
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
|
|
|
27 |
require_once($CFG->dirroot . '/question/type/ddwtos/tests/helper.php');
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Unit tests for the matching question definition class.
|
|
|
32 |
*
|
|
|
33 |
* @package qtype_ddwtos
|
|
|
34 |
* @copyright 2012 The Open University
|
|
|
35 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
36 |
*/
|
1441 |
ariadna |
37 |
final class question_test extends \basic_testcase {
|
1 |
efrain |
38 |
|
11 |
efrain |
39 |
public function test_get_question_summary(): void {
|
1 |
efrain |
40 |
$dd = \test_question_maker::make_question('ddwtos');
|
|
|
41 |
$this->assertEquals('The [[1]] brown [[2]] jumped over the [[3]] dog.; ' .
|
|
|
42 |
'[[1]] -> {quick / slow}; [[2]] -> {fox / dog}; [[3]] -> {lazy / assiduous}',
|
|
|
43 |
$dd->get_question_summary());
|
|
|
44 |
}
|
|
|
45 |
|
11 |
efrain |
46 |
public function test_get_question_summary_maths(): void {
|
1 |
efrain |
47 |
$dd = \test_question_maker::make_question('ddwtos', 'maths');
|
|
|
48 |
$this->assertEquals('Fill in the operators to make this equation work: ' .
|
|
|
49 |
'7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3; [[1]] -> {+ / - / * / /}',
|
|
|
50 |
$dd->get_question_summary());
|
|
|
51 |
}
|
|
|
52 |
|
11 |
efrain |
53 |
public function test_summarise_response(): void {
|
1 |
efrain |
54 |
$dd = \test_question_maker::make_question('ddwtos');
|
|
|
55 |
$dd->shufflechoices = false;
|
|
|
56 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
57 |
|
|
|
58 |
$this->assertEquals('{quick} {fox} {lazy}',
|
|
|
59 |
$dd->summarise_response(array('p1' => '1', 'p2' => '1', 'p3' => '1')));
|
|
|
60 |
}
|
|
|
61 |
|
11 |
efrain |
62 |
public function test_summarise_response_maths(): void {
|
1 |
efrain |
63 |
$dd = \test_question_maker::make_question('ddwtos', 'maths');
|
|
|
64 |
$dd->shufflechoices = false;
|
|
|
65 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
66 |
|
|
|
67 |
$this->assertEquals('{+} {-} {+} {-}',
|
|
|
68 |
$dd->summarise_response(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
|
|
|
69 |
}
|
|
|
70 |
|
11 |
efrain |
71 |
public function test_get_random_guess_score(): void {
|
1 |
efrain |
72 |
$dd = \test_question_maker::make_question('ddwtos');
|
|
|
73 |
$this->assertEquals(0.5, $dd->get_random_guess_score());
|
|
|
74 |
}
|
|
|
75 |
|
11 |
efrain |
76 |
public function test_get_random_guess_score_maths(): void {
|
1 |
efrain |
77 |
$dd = \test_question_maker::make_question('ddwtos', 'maths');
|
|
|
78 |
$this->assertEquals(0.25, $dd->get_random_guess_score());
|
|
|
79 |
}
|
|
|
80 |
|
11 |
efrain |
81 |
public function test_get_right_choice_for(): void {
|
1 |
efrain |
82 |
$dd = \test_question_maker::make_question('ddwtos');
|
|
|
83 |
$dd->shufflechoices = false;
|
|
|
84 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
85 |
|
|
|
86 |
$this->assertEquals(1, $dd->get_right_choice_for(1));
|
|
|
87 |
$this->assertEquals(1, $dd->get_right_choice_for(2));
|
|
|
88 |
}
|
|
|
89 |
|
11 |
efrain |
90 |
public function test_get_right_choice_for_maths(): void {
|
1 |
efrain |
91 |
$dd = \test_question_maker::make_question('ddwtos', 'maths');
|
|
|
92 |
$dd->shufflechoices = false;
|
|
|
93 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
94 |
|
|
|
95 |
$this->assertEquals(1, $dd->get_right_choice_for(1));
|
|
|
96 |
$this->assertEquals(2, $dd->get_right_choice_for(2));
|
|
|
97 |
}
|
|
|
98 |
|
11 |
efrain |
99 |
public function test_clear_wrong_from_response(): void {
|
1 |
efrain |
100 |
$dd = \test_question_maker::make_question('ddwtos', 'maths');
|
|
|
101 |
$dd->shufflechoices = false;
|
|
|
102 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
103 |
|
|
|
104 |
$initialresponse = array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1');
|
|
|
105 |
$this->assertEquals(array('p1' => '1', 'p2' => '0', 'p3' => '1', 'p4' => '0'),
|
|
|
106 |
$dd->clear_wrong_from_response($initialresponse));
|
|
|
107 |
}
|
|
|
108 |
|
11 |
efrain |
109 |
public function test_get_num_parts_right(): void {
|
1 |
efrain |
110 |
$dd = \test_question_maker::make_question('ddwtos');
|
|
|
111 |
$dd->shufflechoices = false;
|
|
|
112 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
113 |
|
|
|
114 |
$this->assertEquals(array(2, 3),
|
|
|
115 |
$dd->get_num_parts_right(array('p1' => '1', 'p2' => '1', 'p3' => '2')));
|
|
|
116 |
$this->assertEquals(array(3, 3),
|
|
|
117 |
$dd->get_num_parts_right(array('p1' => '1', 'p2' => '1', 'p3' => '1')));
|
|
|
118 |
}
|
|
|
119 |
|
11 |
efrain |
120 |
public function test_get_num_parts_right_maths(): void {
|
1 |
efrain |
121 |
$dd = \test_question_maker::make_question('ddwtos', 'maths');
|
|
|
122 |
$dd->shufflechoices = false;
|
|
|
123 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
124 |
|
|
|
125 |
$this->assertEquals(array(2, 4),
|
|
|
126 |
$dd->get_num_parts_right(array(
|
|
|
127 |
'p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
|
|
|
128 |
}
|
|
|
129 |
|
11 |
efrain |
130 |
public function test_get_expected_data(): void {
|
1 |
efrain |
131 |
$dd = \test_question_maker::make_question('ddwtos');
|
|
|
132 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
133 |
|
|
|
134 |
$this->assertEquals(array('p1' => PARAM_INT, 'p2' => PARAM_INT, 'p3' => PARAM_INT),
|
|
|
135 |
$dd->get_expected_data());
|
|
|
136 |
}
|
|
|
137 |
|
11 |
efrain |
138 |
public function test_get_correct_response(): void {
|
1 |
efrain |
139 |
$dd = \test_question_maker::make_question('ddwtos');
|
|
|
140 |
$dd->shufflechoices = false;
|
|
|
141 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
142 |
|
|
|
143 |
$this->assertEquals(array('p1' => '1', 'p2' => '1', 'p3' => '1'),
|
|
|
144 |
$dd->get_correct_response());
|
|
|
145 |
}
|
|
|
146 |
|
11 |
efrain |
147 |
public function test_get_correct_response_maths(): void {
|
1 |
efrain |
148 |
$dd = \test_question_maker::make_question('ddwtos', 'maths');
|
|
|
149 |
$dd->shufflechoices = false;
|
|
|
150 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
151 |
|
|
|
152 |
$this->assertEquals(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2'),
|
|
|
153 |
$dd->get_correct_response());
|
|
|
154 |
}
|
|
|
155 |
|
11 |
efrain |
156 |
public function test_is_same_response(): void {
|
1 |
efrain |
157 |
$dd = \test_question_maker::make_question('ddwtos');
|
|
|
158 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
159 |
|
|
|
160 |
$this->assertTrue($dd->is_same_response(
|
|
|
161 |
array(),
|
|
|
162 |
array('p1' => '0', 'p2' => '0', 'p3' => '0')));
|
|
|
163 |
|
|
|
164 |
$this->assertFalse($dd->is_same_response(
|
|
|
165 |
array(),
|
|
|
166 |
array('p1' => '1', 'p2' => '0', 'p3' => '0')));
|
|
|
167 |
|
|
|
168 |
$this->assertFalse($dd->is_same_response(
|
|
|
169 |
array('p1' => '0', 'p2' => '0', 'p3' => '0'),
|
|
|
170 |
array('p1' => '1', 'p2' => '0', 'p3' => '0')));
|
|
|
171 |
|
|
|
172 |
$this->assertTrue($dd->is_same_response(
|
|
|
173 |
array('p1' => '1', 'p2' => '2', 'p3' => '3'),
|
|
|
174 |
array('p1' => '1', 'p2' => '2', 'p3' => '3')));
|
|
|
175 |
|
|
|
176 |
$this->assertFalse($dd->is_same_response(
|
|
|
177 |
array('p1' => '1', 'p2' => '2', 'p3' => '3'),
|
|
|
178 |
array('p1' => '1', 'p2' => '2', 'p3' => '2')));
|
|
|
179 |
}
|
11 |
efrain |
180 |
public function test_is_complete_response(): void {
|
1 |
efrain |
181 |
$dd = \test_question_maker::make_question('ddwtos');
|
|
|
182 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
183 |
|
|
|
184 |
$this->assertFalse($dd->is_complete_response(array()));
|
|
|
185 |
$this->assertFalse($dd->is_complete_response(
|
|
|
186 |
array('p1' => '1', 'p2' => '1', 'p3' => '0')));
|
|
|
187 |
$this->assertFalse($dd->is_complete_response(array('p1' => '1')));
|
|
|
188 |
$this->assertTrue($dd->is_complete_response(
|
|
|
189 |
array('p1' => '1', 'p2' => '1', 'p3' => '1')));
|
|
|
190 |
}
|
|
|
191 |
|
11 |
efrain |
192 |
public function test_is_gradable_response(): void {
|
1 |
efrain |
193 |
$dd = \test_question_maker::make_question('ddwtos');
|
|
|
194 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
195 |
|
|
|
196 |
$this->assertFalse($dd->is_gradable_response(array()));
|
|
|
197 |
$this->assertFalse($dd->is_gradable_response(
|
|
|
198 |
array('p1' => '0', 'p2' => '0', 'p3' => '0')));
|
|
|
199 |
$this->assertTrue($dd->is_gradable_response(
|
|
|
200 |
array('p1' => '1', 'p2' => '1', 'p3' => '0')));
|
|
|
201 |
$this->assertTrue($dd->is_gradable_response(array('p1' => '1')));
|
|
|
202 |
$this->assertTrue($dd->is_gradable_response(
|
|
|
203 |
array('p1' => '1', 'p2' => '1', 'p3' => '1')));
|
|
|
204 |
}
|
|
|
205 |
|
11 |
efrain |
206 |
public function test_grading(): void {
|
1 |
efrain |
207 |
$dd = \test_question_maker::make_question('ddwtos');
|
|
|
208 |
$dd->shufflechoices = false;
|
|
|
209 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
210 |
|
|
|
211 |
$this->assertEquals(array(1, question_state::$gradedright),
|
|
|
212 |
$dd->grade_response(array('p1' => '1', 'p2' => '1', 'p3' => '1')));
|
|
|
213 |
$this->assertEquals(array(1 / 3, question_state::$gradedpartial),
|
|
|
214 |
$dd->grade_response(array('p1' => '1')));
|
|
|
215 |
$this->assertEquals(array(0, question_state::$gradedwrong),
|
|
|
216 |
$dd->grade_response(array('p1' => '2', 'p2' => '2', 'p3' => '2')));
|
|
|
217 |
}
|
|
|
218 |
|
11 |
efrain |
219 |
public function test_grading_maths(): void {
|
1 |
efrain |
220 |
$dd = \test_question_maker::make_question('ddwtos', 'maths');
|
|
|
221 |
$dd->shufflechoices = false;
|
|
|
222 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
223 |
|
|
|
224 |
$this->assertEquals(array(1, question_state::$gradedright),
|
|
|
225 |
$dd->grade_response(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
|
|
|
226 |
$this->assertEquals(array(0.5, question_state::$gradedpartial),
|
|
|
227 |
$dd->grade_response(array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
|
|
|
228 |
$this->assertEquals(array(0, question_state::$gradedwrong),
|
|
|
229 |
$dd->grade_response(array('p1' => '0', 'p2' => '1', 'p3' => '2', 'p4' => '1')));
|
|
|
230 |
}
|
|
|
231 |
|
11 |
efrain |
232 |
public function test_classify_response(): void {
|
1 |
efrain |
233 |
$dd = \test_question_maker::make_question('ddwtos');
|
|
|
234 |
$dd->shufflechoices = false;
|
|
|
235 |
$dd->start_attempt(new question_attempt_step(), 1);
|
|
|
236 |
|
|
|
237 |
$this->assertEquals(array(
|
|
|
238 |
1 => new question_classified_response(1, 'quick', 1 / 3),
|
|
|
239 |
2 => new question_classified_response(2, 'dog', 0),
|
|
|
240 |
3 => new question_classified_response(1, 'lazy', 1 / 3),
|
|
|
241 |
), $dd->classify_response(array('p1' => '1', 'p2' => '2', 'p3' => '1')));
|
|
|
242 |
$this->assertEquals(array(
|
|
|
243 |
1 => question_classified_response::no_response(),
|
|
|
244 |
2 => new question_classified_response(1, 'fox', 1 / 3),
|
|
|
245 |
3 => new question_classified_response(2, 'assiduous', 0),
|
|
|
246 |
), $dd->classify_response(array('p1' => '0', 'p2' => '1', 'p3' => '2')));
|
|
|
247 |
}
|
|
|
248 |
}
|