14
14
// You should have received a copy of the GNU General Public License
15
15
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
16
17
- /**
18
- * Unit tests for the varnumericset question definition class.
19
- *
20
- * @package qtype_varnumericset
21
- * @copyright 2012 The Open University
22
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
- */
17
+ namespace qtype_varnumericset ;
24
18
19
+ use advanced_testcase ;
20
+ use qtype_varnumeric_question_base ;
21
+ use qtype_varnumericset_answer ;
22
+ use qtype_varnumericset_question ;
23
+ use question_attempt_step ;
24
+ use test_question_maker ;
25
25
26
26
defined ('MOODLE_INTERNAL ' ) || die ();
27
27
global $ CFG ;
33
33
/**
34
34
* Unit tests for the varnumericset question definition class.
35
35
*
36
+ * @package qtype_varnumericset
36
37
* @copyright 2012 The Open University
37
38
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
- * @covers \qtype_varnumeric_question_base
39
- * @covers \qtype_varnumericset_question
39
+ * @covers \qtype_varnumeric_question_base
40
+ * @covers \qtype_varnumericset_question
40
41
*/
41
42
class question_test extends advanced_testcase {
42
43
@@ -45,7 +46,7 @@ class question_test extends advanced_testcase {
45
46
*
46
47
* @return array of arrays of arguments for test_num_within_allowed_error
47
48
*/
48
- public function num_within_allowed_error_cases (): array {
49
+ public static function num_within_allowed_error_cases (): array {
49
50
return [
50
51
['1.23000000000001e4 ' , 1.23e4 , '' , true ],
51
52
['1.23000000000002e4 ' , 1.23e4 , '' , false ],
@@ -83,7 +84,7 @@ public function num_within_allowed_error_cases(): array {
83
84
/**
84
85
* @dataProvider num_within_allowed_error_cases
85
86
*/
86
- public function test_num_within_allowed_error ($ response , $ answer , $ allowederror , $ shouldmatch ) {
87
+ public function test_num_within_allowed_error ($ response , $ answer , $ allowederror , $ shouldmatch ): void {
87
88
if ($ shouldmatch ) {
88
89
$ this ->assertTrue (
89
90
qtype_varnumeric_question_base::num_within_allowed_error ($ response , $ answer , $ allowederror ));
@@ -98,7 +99,7 @@ public function test_num_within_allowed_error($response, $answer, $allowederror,
98
99
*
99
100
* @return array of arrays of arguments for test_num_within_allowed_error
100
101
*/
101
- public function wrong_by_a_factor_of_ten_cases (): array {
102
+ public static function wrong_by_a_factor_of_ten_cases (): array {
102
103
return [
103
104
['1.23e4 ' , 1.23e5 , '' , 1 , true ],
104
105
['1.23e4 ' , 1.23e6 , '' , 1 , false ],
@@ -112,7 +113,7 @@ public function wrong_by_a_factor_of_ten_cases(): array {
112
113
/**
113
114
* @dataProvider wrong_by_a_factor_of_ten_cases
114
115
*/
115
- public function test_wrong_by_a_factor_of_ten ($ response , $ roundedanswer , $ allowederror , $ maxfactor , $ shouldmatch ) {
116
+ public function test_wrong_by_a_factor_of_ten ($ response , $ roundedanswer , $ allowederror , $ maxfactor , $ shouldmatch ): void {
116
117
if ($ shouldmatch ) {
117
118
$ this ->assertTrue (
118
119
qtype_varnumeric_question_base::wrong_by_a_factor_of_ten (
@@ -124,7 +125,7 @@ public function test_wrong_by_a_factor_of_ten($response, $roundedanswer, $allowe
124
125
}
125
126
}
126
127
127
- public function test_has_number_of_sig_figs () {
128
+ public function test_has_number_of_sig_figs (): void {
128
129
$ this ->assertTrue (
129
130
qtype_varnumericset_question::has_number_of_sig_figs ('1.23e4 ' , 3 ));
130
131
@@ -169,7 +170,7 @@ public function test_has_number_of_sig_figs() {
169
170
qtype_varnumericset_question::has_number_of_sig_figs ('15.0 ' , 2 ));
170
171
}
171
172
172
- public function test_has_too_many_sig_figs () {
173
+ public function test_has_too_many_sig_figs (): void {
173
174
$ this ->assertTrue (qtype_varnumericset_question::has_too_many_sig_figs ('1.23456e5 ' , 123456 , 2 ));
174
175
$ this ->assertTrue (qtype_varnumericset_question::has_too_many_sig_figs ('1.23456e5 ' , 123456 , 3 ));
175
176
$ this ->assertTrue (qtype_varnumericset_question::has_too_many_sig_figs ('1.23456e5 ' , 123456 , 4 ));
@@ -210,7 +211,7 @@ public function test_has_too_many_sig_figs() {
210
211
qtype_varnumericset_question::has_too_many_sig_figs ('-1.23456e-12 ' , -1.2346e-12 , 4 ));
211
212
}
212
213
213
- public function test_rounding_incorrect () {
214
+ public function test_rounding_incorrect (): void {
214
215
$ this ->assertTrue (
215
216
qtype_varnumericset_question::rounding_incorrect ('1.234 ' , 1.2345 , 4 ));
216
217
$ this ->assertTrue (
@@ -228,7 +229,7 @@ public function test_rounding_incorrect() {
228
229
*
229
230
* @return array of arrays of arguments for test_num_within_allowed_error
230
231
*/
231
- public function round_to_cases (): array {
232
+ public static function round_to_cases (): array {
232
233
return [
233
234
['0.123 ' , 0.12345 , 3 , false , false ],
234
235
['0.1235 ' , 0.12345 , 4 , false , false ],
@@ -254,7 +255,7 @@ public function round_to_cases(): array {
254
255
/**
255
256
* @dataProvider round_to_cases
256
257
*/
257
- public function test_round_to ($ expected , $ number , $ sigfigs , $ scinotation , $ floor ) {
258
+ public function test_round_to ($ expected , $ number , $ sigfigs , $ scinotation , $ floor ): void {
258
259
$ this ->assertSame ($ expected ,
259
260
qtype_varnumeric_question_base::round_to ($ number , $ sigfigs , $ scinotation , $ floor ));
260
261
}
@@ -271,7 +272,7 @@ protected function grade(qtype_varnumericset_question $question, string $entered
271
272
return $ fraction ;
272
273
}
273
274
274
- public function test_compare_response_with_answer () {
275
+ public function test_compare_response_with_answer (): void {
275
276
/** @var qtype_varnumericset_question $q */
276
277
$ q = test_question_maker::make_question ('varnumericset ' ); // Does not matter which one.
277
278
@@ -318,7 +319,8 @@ public function test_compare_response_with_answer() {
318
319
$ this ->assertNull ($ answertoreturn );
319
320
}
320
321
321
- public function test_compare_num_as_string_with_answer () {
322
+ public function test_compare_num_as_string_with_answer (): void {
323
+ /** @var qtype_varnumericset_question $q */
322
324
$ q = test_question_maker::make_question ('varnumericset ' ); // Does not matter which one.
323
325
324
326
$ answer = new qtype_varnumericset_answer (12345 , // Id.
@@ -335,7 +337,6 @@ public function test_compare_num_as_string_with_answer() {
335
337
'0 ' , // Checkrounding.
336
338
'0 ' ); // Checkscinotationformat.
337
339
338
- /** @var qtype_varnumericset_question $q */
339
340
[$ penalty ] = $ q ->compare_num_as_string_with_answer (
340
341
'-4.20 ' , $ answer );
341
342
$ this ->assertEquals (0 , $ penalty );
@@ -369,6 +370,7 @@ public function test_compare_num_as_string_with_answer() {
369
370
$ this ->assertEquals (1 , $ penalty );
370
371
371
372
// Test check scinotation format.
373
+ /** @var qtype_varnumericset_question $question */
372
374
$ question = test_question_maker::make_question ('varnumericset ' , 'sci_notation_formatted ' );
373
375
$ answer = new qtype_varnumericset_answer (12345 , // Id.
374
376
'12 ' , // Answer.
@@ -416,7 +418,8 @@ public function test_compare_num_as_string_with_answer() {
416
418
$ this ->assertEquals (0.25 , $ penalty );
417
419
}
418
420
419
- public function test_compare_num_as_string_with_answer_no_rounding () {
421
+ public function test_compare_num_as_string_with_answer_no_rounding (): void {
422
+ /** @var qtype_varnumericset_question $q */
420
423
$ q = test_question_maker::make_question ('varnumericset ' ); // Does not matter which one.
421
424
422
425
$ answer = new qtype_varnumericset_answer (12345 , // Id.
@@ -433,12 +436,11 @@ public function test_compare_num_as_string_with_answer_no_rounding() {
433
436
'0 ' , // Checkrounding.
434
437
'0 ' ); // Checkscinotationformat.
435
438
436
- /** @var qtype_varnumericset_question $q */
437
439
[$ penalty ] = $ q ->compare_num_as_string_with_answer ('123456789 ' , $ answer );
438
440
$ this ->assertEquals (0 , $ penalty );
439
441
}
440
442
441
- public function test_grade_response () {
443
+ public function test_grade_response (): void {
442
444
/** @var qtype_varnumericset_question $question */
443
445
$ question = test_question_maker::make_question ('varnumericset ' , 'no_accepted_error ' );
444
446
$ this ->assertEquals (1 , $ this ->grade ($ question , '-4.2 ' ));
@@ -529,7 +531,7 @@ public function test_grade_response() {
529
531
$ this ->assertEquals (0.75 , $ this ->grade ($ question , '1.200000 x 10<sup>+ 1</sup> ' ));
530
532
}
531
533
532
- public function test_get_question_summary () {
534
+ public function test_get_question_summary (): void {
533
535
$ question = test_question_maker::make_question ('varnumericset ' , 'with_variables ' );
534
536
$ question ->start_attempt (new question_attempt_step (), 1 );
535
537
$ this ->assertEquals ('What is 2 + 3? ' , $ question ->get_question_summary ());
0 commit comments