Skip to content

Commit bc02e6b

Browse files
committed
More coding style fixes
1 parent 812094f commit bc02e6b

9 files changed

+80
-111
lines changed

tests/behat/preview.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Feature: Preview a Variable numeric set question
3030
| Marked out of | 3 |
3131
| Question variant | 1 |
3232
| Marks | Show mark and max |
33-
And I press "Start again with these options"
33+
And I press "id_saverestart"
3434
Then I should see "What is 2 + 8?"
3535
And the state of "What is 2 + 8?" question is shown as "Tries remaining: 3"
3636
When I set the field "Answer:" to "2"

tests/calculator_test.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function test_evaluate_variables_in_text(string $variable, string $expect
8282
*
8383
* @return array List of data sets (test cases).
8484
*/
85-
public function evaluate_variables_in_text_provider(): array {
85+
public static function evaluate_variables_in_text_provider(): array {
8686

8787
return [
8888
'The argument is treated as an integer and presented as a binary number' => [

tests/evalmath_test.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* @covers \EvalMath
3535
*/
3636
class evalmath_test extends basic_testcase {
37-
public function test_basic_expressions() {
37+
public function test_basic_expressions(): void {
3838
$ev = new EvalMath(true, true);
3939

4040
$this->assertEquals(2, $ev->evaluate('a=2'));
@@ -46,7 +46,7 @@ public function test_basic_expressions() {
4646
$this->assertEquals(2, $ev->evaluate('a'));
4747

4848
}
49-
public function test_random_expressions() {
49+
public function test_random_expressions(): void {
5050
$ev = new EvalMath(true, true);
5151
$results = [];
5252
for ($i = 0; $i < 500; $i++) {

tests/form_test.php

+13-20
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@
1616

1717
namespace qtype_varnumericset;
1818

19-
/**
20-
* Unit tests for the varnumericset question edit form.
21-
*
22-
* @package qtype_varnumericset
23-
* @copyright 2023 The Open University
24-
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25-
*/
26-
2719
defined('MOODLE_INTERNAL') || die();
2820
global $CFG;
2921

@@ -33,6 +25,7 @@
3325
/**
3426
* Unit tests for the qtype_varnumericset question edit form.
3527
*
28+
* @package qtype_varnumericset
3629
* @copyright 2023 The Open University
3730
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3831
* @covers \qtype_varnumeric_edit_form_base
@@ -104,7 +97,7 @@ public function test_form_validation(array $fromform, array $expectederrors): vo
10497
*
10598
* @return array List of data sets (test cases).
10699
*/
107-
public function form_validation_testcases(): array {
100+
public static function form_validation_testcases(): array {
108101
return [
109102
'All OK' => [
110103
[
@@ -145,20 +138,20 @@ public function form_validation_testcases(): array {
145138
],
146139
[
147140
'questiontext' => get_string('errorvalidationformatnumber', 'qtype_varnumericset',
148-
'[[x.e]] - Expression evaluation error: an unexpected error occurred.'),
141+
'[[x.e]] - Expression evaluation error: an unexpected error occurred.'),
149142
'generalfeedback' => get_string('errorvalidationformatnumber', 'qtype_varnumericset',
150-
'[[x.e]] - Expression evaluation error: an unexpected error occurred.'),
143+
'[[x.e]] - Expression evaluation error: an unexpected error occurred.'),
151144
'feedback[0]' => get_string('errorvalidationformatnumber', 'qtype_varnumericset',
152-
"[[x,&nbsp;.e]] - The format specifier must not contain non-breaking space characters."),
145+
"[[x,&nbsp;.e]] - The format specifier must not contain non-breaking space characters."),
153146
'feedback[1]' => get_string('errorvalidationformatnumber', 'qtype_varnumericset',
154-
'[[x,]] - Missing format specifier at end of string.'),
147+
'[[x,]] - Missing format specifier at end of string.'),
155148
'hint[0]' => get_string('errorvalidationformatnumber', 'qtype_varnumericset',
156-
'[[x,i]] - Unknown format specifier &quot;i&quot;.'),
149+
'[[x,i]] - Unknown format specifier &quot;i&quot;.'),
157150
'hint[1]' => get_string('errorvalidationformatnumber', 'qtype_varnumericset',
158-
'[[x,.3\'.09 f]] - Unknown format specifier &quot;&#039;&quot;.'),
151+
'[[x,.3\'.09 f]] - Unknown format specifier &quot;&#039;&quot;.'),
159152
'hint[2]' => get_string('errorvalidationformatnumber', 'qtype_varnumericset',
160-
"<ul>\n<li>[[x,]] - Missing format specifier at end of string.</li>\n" .
161-
"<li>[[x,i]] - Unknown format specifier &quot;i&quot;.</li>\n</ul>"),
153+
"<ul>\n<li>[[x,]] - Missing format specifier at end of string.</li>\n" .
154+
"<li>[[x,i]] - Unknown format specifier &quot;i&quot;.</li>\n</ul>"),
162155
],
163156
],
164157
[
@@ -172,9 +165,9 @@ public function form_validation_testcases(): array {
172165
'variant1' => [],
173166
],
174167
[
175-
'vartype[0]' => 'At least one of the variables must be a predefined variable.'
176-
]
177-
]
168+
'vartype[0]' => 'At least one of the variables must be a predefined variable.',
169+
],
170+
],
178171
];
179172
}
180173
}

tests/helper.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,12 @@ public function get_varnumericset_question_form_data_sci_notation_formatted() {
322322
$form->fraction = ['0' => '1.0', '1' => '0.0', '2' => '0.0'];
323323
$form->feedback = [
324324
'0' => ['format' => FORMAT_HTML, 'text' => 'Well done!'],
325-
'1' => ['format' => FORMAT_HTML, 'text' => 'Sorry, no.']
325+
'1' => ['format' => FORMAT_HTML, 'text' => 'Sorry, no.'],
326326
];
327327
$form->penalty = '0.3333333';
328328
$form->hint = [
329329
['text' => 'Please try again.', 'format' => FORMAT_HTML],
330-
['text' => 'You may use a calculator if necessary.', 'format' => FORMAT_HTML]
330+
['text' => 'You may use a calculator if necessary.', 'format' => FORMAT_HTML],
331331
];
332332

333333
return $form;
@@ -340,19 +340,19 @@ public function make_varnumericset_question_sci_notation_formatted() {
340340
$vs = $this->make_varnumericset_question_no_accepted_error();
341341

342342
$vs->answers = [1 => new qtype_varnumericset_answer(
343-
'1', // Id.
344-
'12', // Answer.
345-
1.0000000, // Fraction.
343+
'1', // Id.
344+
'12', // Answer.
345+
1.0000000, // Fraction.
346346
'<p>Your answer is correct.</p>', // Feedback.
347-
FORMAT_HTML,// Feedbackformat.
348-
'0', // Sigfigs.
349-
'', // Error.
350-
'0.25', // Syserrorpenalty.
351-
'0', // Checknumerical.
352-
'1', // Checkscinotation.
353-
'0', // Checkpowerof10.
354-
'0', // Checkrounding.
355-
'1', // Checkscinotationformat.
347+
FORMAT_HTML, // Feedbackformat.
348+
'0', // Sigfigs.
349+
'', // Error.
350+
'0.25', // Syserrorpenalty.
351+
'0', // Checknumerical.
352+
'1', // Checkscinotation.
353+
'0', // Checkpowerof10.
354+
'0', // Checkrounding.
355+
'1', // Checkscinotationformat.
356356
)];
357357
$vs->requirescinotation = true;
358358
$vs->usesupeditor = true;

tests/number_interpreter_test.php

+6-15
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,22 @@
2020
use qtype_varnumericset_number_interpreter_number_with_optional_decimal_place;
2121
use qtype_varnumericset_number_interpreter_number_with_optional_sci_notation;
2222

23-
/**
24-
* Unit tests for the number interpreter classes .
25-
*
26-
* @package qtype_varnumericset
27-
* @copyright 2012 The Open University
28-
* @author Jamie Pratt me@jamiep.org
29-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30-
*/
31-
32-
3323
defined('MOODLE_INTERNAL') || die();
3424
global $CFG;
3525

3626
require_once($CFG->dirroot . '/question/type/varnumericset/number_interpreter.php');
3727

38-
3928
/**
4029
* Unit tests for the number interpreter classes .
4130
*
31+
* @package qtype_varnumericset
4232
* @copyright 2012 The Open University
4333
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44-
* @group qtype_varnumericset
34+
* @covers \qtype_varnumericset_number_interpreter_number_with_optional_decimal_place
35+
* @covers \qtype_varnumericset_number_interpreter_number_with_optional_sci_notation
4536
*/
4637
class number_interpreter_test extends basic_testcase {
47-
public function test_interpret_number_with_optional_decimal_place() {
38+
public function test_interpret_number_with_optional_decimal_place(): void {
4839
$num = new qtype_varnumericset_number_interpreter_number_with_optional_decimal_place();
4940

5041
$this->assertFalse($num->match('newt'));
@@ -91,7 +82,7 @@ public function test_interpret_number_with_optional_decimal_place() {
9182
$this->assertSame('', $num->get_postfix());
9283
}
9384

94-
public function test_interpret_number_with_optional_sci_notation_not_accepting_html_exponent() {
85+
public function test_interpret_number_with_optional_sci_notation_not_accepting_html_exponent(): void {
9586
$num = new qtype_varnumericset_number_interpreter_number_with_optional_sci_notation(false);
9687

9788
$this->assertFalse($num->match('newt'));
@@ -155,7 +146,7 @@ public function test_interpret_number_with_optional_sci_notation_not_accepting_h
155146
$this->assertSame('m', $num->get_postfix());
156147
}
157148

158-
public function test_interpret_number_with_optional_sci_notation_accepting_html_exponent() {
149+
public function test_interpret_number_with_optional_sci_notation_accepting_html_exponent(): void {
159150
$num = new qtype_varnumericset_number_interpreter_number_with_optional_sci_notation(true);
160151

161152
$this->assertFalse($num->match('newt'));

tests/question_test.php

+27-25
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

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;
2418

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;
2525

2626
defined('MOODLE_INTERNAL') || die();
2727
global $CFG;
@@ -33,10 +33,11 @@
3333
/**
3434
* Unit tests for the varnumericset question definition class.
3535
*
36+
* @package qtype_varnumericset
3637
* @copyright 2012 The Open University
3738
* @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
4041
*/
4142
class question_test extends advanced_testcase {
4243

@@ -45,7 +46,7 @@ class question_test extends advanced_testcase {
4546
*
4647
* @return array of arrays of arguments for test_num_within_allowed_error
4748
*/
48-
public function num_within_allowed_error_cases(): array {
49+
public static function num_within_allowed_error_cases(): array {
4950
return [
5051
['1.23000000000001e4', 1.23e4, '', true],
5152
['1.23000000000002e4', 1.23e4, '', false],
@@ -83,7 +84,7 @@ public function num_within_allowed_error_cases(): array {
8384
/**
8485
* @dataProvider num_within_allowed_error_cases
8586
*/
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 {
8788
if ($shouldmatch) {
8889
$this->assertTrue(
8990
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,
9899
*
99100
* @return array of arrays of arguments for test_num_within_allowed_error
100101
*/
101-
public function wrong_by_a_factor_of_ten_cases(): array {
102+
public static function wrong_by_a_factor_of_ten_cases(): array {
102103
return [
103104
['1.23e4', 1.23e5, '', 1, true],
104105
['1.23e4', 1.23e6, '', 1, false],
@@ -112,7 +113,7 @@ public function wrong_by_a_factor_of_ten_cases(): array {
112113
/**
113114
* @dataProvider wrong_by_a_factor_of_ten_cases
114115
*/
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 {
116117
if ($shouldmatch) {
117118
$this->assertTrue(
118119
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
124125
}
125126
}
126127

127-
public function test_has_number_of_sig_figs() {
128+
public function test_has_number_of_sig_figs(): void {
128129
$this->assertTrue(
129130
qtype_varnumericset_question::has_number_of_sig_figs('1.23e4', 3));
130131

@@ -169,7 +170,7 @@ public function test_has_number_of_sig_figs() {
169170
qtype_varnumericset_question::has_number_of_sig_figs('15.0', 2));
170171
}
171172

172-
public function test_has_too_many_sig_figs() {
173+
public function test_has_too_many_sig_figs(): void {
173174
$this->assertTrue(qtype_varnumericset_question::has_too_many_sig_figs('1.23456e5', 123456, 2));
174175
$this->assertTrue(qtype_varnumericset_question::has_too_many_sig_figs('1.23456e5', 123456, 3));
175176
$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() {
210211
qtype_varnumericset_question::has_too_many_sig_figs('-1.23456e-12', -1.2346e-12, 4));
211212
}
212213

213-
public function test_rounding_incorrect() {
214+
public function test_rounding_incorrect(): void {
214215
$this->assertTrue(
215216
qtype_varnumericset_question::rounding_incorrect('1.234', 1.2345, 4));
216217
$this->assertTrue(
@@ -228,7 +229,7 @@ public function test_rounding_incorrect() {
228229
*
229230
* @return array of arrays of arguments for test_num_within_allowed_error
230231
*/
231-
public function round_to_cases(): array {
232+
public static function round_to_cases(): array {
232233
return [
233234
['0.123', 0.12345, 3, false, false],
234235
['0.1235', 0.12345, 4, false, false],
@@ -254,7 +255,7 @@ public function round_to_cases(): array {
254255
/**
255256
* @dataProvider round_to_cases
256257
*/
257-
public function test_round_to($expected, $number, $sigfigs, $scinotation, $floor) {
258+
public function test_round_to($expected, $number, $sigfigs, $scinotation, $floor): void {
258259
$this->assertSame($expected,
259260
qtype_varnumeric_question_base::round_to($number, $sigfigs, $scinotation, $floor));
260261
}
@@ -271,7 +272,7 @@ protected function grade(qtype_varnumericset_question $question, string $entered
271272
return $fraction;
272273
}
273274

274-
public function test_compare_response_with_answer() {
275+
public function test_compare_response_with_answer(): void {
275276
/** @var qtype_varnumericset_question $q */
276277
$q = test_question_maker::make_question('varnumericset'); // Does not matter which one.
277278

@@ -318,7 +319,8 @@ public function test_compare_response_with_answer() {
318319
$this->assertNull($answertoreturn);
319320
}
320321

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 */
322324
$q = test_question_maker::make_question('varnumericset'); // Does not matter which one.
323325

324326
$answer = new qtype_varnumericset_answer(12345, // Id.
@@ -335,7 +337,6 @@ public function test_compare_num_as_string_with_answer() {
335337
'0', // Checkrounding.
336338
'0'); // Checkscinotationformat.
337339

338-
/** @var qtype_varnumericset_question $q */
339340
[$penalty] = $q->compare_num_as_string_with_answer(
340341
'-4.20', $answer);
341342
$this->assertEquals(0, $penalty);
@@ -369,6 +370,7 @@ public function test_compare_num_as_string_with_answer() {
369370
$this->assertEquals(1, $penalty);
370371

371372
// Test check scinotation format.
373+
/** @var qtype_varnumericset_question $question */
372374
$question = test_question_maker::make_question('varnumericset', 'sci_notation_formatted');
373375
$answer = new qtype_varnumericset_answer(12345, // Id.
374376
'12', // Answer.
@@ -416,7 +418,8 @@ public function test_compare_num_as_string_with_answer() {
416418
$this->assertEquals(0.25, $penalty);
417419
}
418420

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 */
420423
$q = test_question_maker::make_question('varnumericset'); // Does not matter which one.
421424

422425
$answer = new qtype_varnumericset_answer(12345, // Id.
@@ -433,12 +436,11 @@ public function test_compare_num_as_string_with_answer_no_rounding() {
433436
'0', // Checkrounding.
434437
'0'); // Checkscinotationformat.
435438

436-
/** @var qtype_varnumericset_question $q */
437439
[$penalty] = $q->compare_num_as_string_with_answer('123456789', $answer);
438440
$this->assertEquals(0, $penalty);
439441
}
440442

441-
public function test_grade_response() {
443+
public function test_grade_response(): void {
442444
/** @var qtype_varnumericset_question $question */
443445
$question = test_question_maker::make_question('varnumericset', 'no_accepted_error');
444446
$this->assertEquals(1, $this->grade($question, '-4.2'));
@@ -529,7 +531,7 @@ public function test_grade_response() {
529531
$this->assertEquals(0.75, $this->grade($question, '1.200000 x 10<sup>+ 1</sup>'));
530532
}
531533

532-
public function test_get_question_summary() {
534+
public function test_get_question_summary(): void {
533535
$question = test_question_maker::make_question('varnumericset', 'with_variables');
534536
$question->start_attempt(new question_attempt_step(), 1);
535537
$this->assertEquals('What is 2 + 3?', $question->get_question_summary());

0 commit comments

Comments
 (0)