Skip to content

Commit

Permalink
Fix coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Nov 2, 2023
1 parent f95c8a6 commit 842f76b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
25 changes: 10 additions & 15 deletions tests/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Unit tests for ou matrix question type.
* Unit tests helper for the OU matrix question type.
*
* @package qtype_oumatrix
* @copyright 2023 The Open University
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_oumatrix_test_helper extends question_test_helper {

/**
* Returns the test questions.
*
* @return string[]
*/
public function get_test_questions(): array {
return [
'animals_single',
Expand All @@ -38,9 +33,9 @@ public function get_test_questions(): array {
/**
* Get the question data, as it would be loaded by get_question_options.
*
* @return object
* @return stdClass
*/
public function get_oumatrix_question_data_animals_single(): object {
public function get_oumatrix_question_data_animals_single(): stdClass {
global $USER;

$qdata = new stdClass();
Expand Down Expand Up @@ -151,9 +146,9 @@ public function get_oumatrix_question_data_animals_single(): object {
/**
* Get the question data, as it would be loaded by get_question_options.
*
* @return object
* @return stdClass
*/
public static function get_oumatrix_question_form_data_animals_single(): object {
public static function get_oumatrix_question_form_data_animals_single(): stdClass {
$qfdata = new stdClass();

$qfdata->name = 'oumatrix_animals_single01';
Expand Down Expand Up @@ -232,9 +227,9 @@ public static function get_oumatrix_question_form_data_animals_single(): object
/**
* Get the question data, as it would be loaded by get_question_options.
*
* @return object
* @return stdClass
*/
public function get_oumatrix_question_data_food_multiple(): object {
public function get_oumatrix_question_data_food_multiple(): stdClass {
global $USER;

$qdata = new stdClass();
Expand Down Expand Up @@ -352,9 +347,9 @@ public function get_oumatrix_question_data_food_multiple(): object {
/**
* Get the question data, as it would be loaded by get_question_options.
*
* @return object
* @return stdClass
*/
public static function get_oumatrix_question_form_data_food_multiple(): object {
public static function get_oumatrix_question_form_data_food_multiple(): stdClass {
$qfdata = new stdClass();

$qfdata->name = 'oumatrix_food_multiple01';
Expand Down Expand Up @@ -544,4 +539,4 @@ public function make_oumatrix_question_animals_single(): qtype_oumatrix_single {
];
return $question;
}
}
}
32 changes: 18 additions & 14 deletions tests/question_single_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@
*/
class question_single_test extends \advanced_testcase {

public function test_get_expected_data() {
public function test_get_expected_data(): void {
$question = \test_question_maker::make_question('oumatrix');
$question->start_attempt(new question_attempt_step(), 1);

$expected = ['rowanswers0' => PARAM_INT, 'rowanswers1' => PARAM_INT,
'rowanswers2' => PARAM_INT, 'rowanswers3' => PARAM_INT];
$this->assertEquals($expected , $question->get_expected_data());
$expected = [
'rowanswers0' => PARAM_INT,
'rowanswers1' => PARAM_INT,
'rowanswers2' => PARAM_INT,
'rowanswers3' => PARAM_INT,
];
$this->assertEquals($expected, $question->get_expected_data());
}

public function test_is_gradable_response() {
public function test_is_gradable_response(): void {
$question = \test_question_maker::make_question('oumatrix');
$question->start_attempt(new question_attempt_step(), 1);

Expand All @@ -56,7 +60,7 @@ public function test_is_gradable_response() {
$this->assertEquals($question->is_gradable_response($response), $question->is_complete_response($response));
}

public function test_is_same_response() {
public function test_is_same_response(): void {
$question = \test_question_maker::make_question('oumatrix');
$question->start_attempt(new question_attempt_step(), 1);

Expand All @@ -83,14 +87,14 @@ public function test_is_same_response() {
['rowanswers0' => '1', 'rowanswers1' => '2', 'rowanswers2' => '3', 'rowanswers3' => '4']));
}

public function test_get_correct_response() {
public function test_get_correct_response(): void {
$question = \test_question_maker::make_question('oumatrix', 'animals_single');
$question->start_attempt(new question_attempt_step(), 1);
$correct = ['rowanswers0' => '1', 'rowanswers1' => '2', 'rowanswers2' => '3', 'rowanswers3' => '4'];
$this->assertEquals($correct, $question->get_correct_response());
}

public function test_summarise_response() {
public function test_summarise_response(): void {
$question = \test_question_maker::make_question('oumatrix', 'animals_single');
$question->start_attempt(new question_attempt_step(), 1);

Expand All @@ -115,15 +119,15 @@ public function test_summarise_response() {
$this->assertMatchesRegularExpression($expected, $actual);
}

public function test_is_complete_response() {
public function test_is_complete_response(): void {
$question = \test_question_maker::make_question('oumatrix');
$question->start_attempt(new question_attempt_step(), 1);

// Not complete responses
// Not complete responses.
$this->assertFalse($question->is_complete_response([]));
$this->assertFalse($question->is_complete_response(['rowanswers0' => '1']));
$this->assertFalse($question->is_complete_response(['rowanswers0' => '1', 'rowanswers1' => '2']));
$this->assertFalse($question->is_complete_response(['rowanswers0' => '1', 'rowanswers1' => '2', 'rowanswers1' => '3']));
$this->assertFalse($question->is_complete_response(['rowanswers0' => '1', 'rowanswers1' => '2', 'rowanswers2' => '3']));

// Complete responses.
$this->assertTrue($question->is_complete_response(
Expand All @@ -134,7 +138,7 @@ public function test_is_complete_response() {
['rowanswers0' => '4', 'rowanswers1' => '3', 'rowanswers2' => '2', 'rowanswers3' => '1'])); // Incorrect.
}

public function test_grade_response() {
public function test_grade_response(): void {
$question = \test_question_maker::make_question('oumatrix', 'animals_single');
$question->start_attempt(new question_attempt_step(), 1);

Expand All @@ -148,10 +152,10 @@ public function test_grade_response() {
$this->assertEquals([0.75, question_state::$gradedpartial], $question->grade_response($partialresponse));

$wrongresponse = ['rowanswers0' => '4', 'rowanswers1' => '3', 'rowanswers2' => '2', 'rowanswers3' => '1'];
$this->assertEquals(array(0, question_state::$gradedwrong), $question->grade_response($wrongresponse));
$this->assertEquals([0, question_state::$gradedwrong], $question->grade_response($wrongresponse));
}

public function test_get_num_parts_right() {
public function test_get_num_parts_right(): void {
$question = \test_question_maker::make_question('oumatrix');

$question->start_attempt(new question_attempt_step(), 1);
Expand Down

0 comments on commit 842f76b

Please sign in to comment.