Skip to content

Commit

Permalink
test validation and robustness of grading vars
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippImhof committed Nov 17, 2023
1 parent 04b6dce commit ef913f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/behat/edit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,14 @@ Feature: Test editing a Formulas question
And I set the field "Answer for part 3" to "7"
And I press "Check"
And I should see "Correct"

Scenario: Check validation of grading vars
When I am on the "formulas-001 for editing" "core_question > edit" page logged in as teacher1
And I set the following fields to these values:
| Grading variables | test = 1/0; |
And I press "id_submitbutton"
Then I should see "Try evalution error! 1: Some expressions cannot be evaluated numerically."
And I set the following fields to these values:
| Grading variables | test = 2; |
And I press "id_submitbutton"
Then I should not see "Try evalution error! 1: Some expressions cannot be evaluated numerically."
22 changes: 22 additions & 0 deletions tests/question_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,28 @@ public function test_grade_parts_that_can_be_graded_test3() {
$this->assertEquals($expected, $partscores);
}

public function test_with_invalidated_grading_vars() {
$q = $this->get_test_formulas_question('testtwonums');

// Set the grading vars to _0/_1 which will be invalid if the student
// enters 0 as their second answer.
$q->parts[0]->vars2 = 'test = _0/_1';
$q->parts[0]->correctness = 'test';
$q->parts[0]->numbox = 2;
$q->start_attempt(new question_attempt_step(), 1);

// The invalid grading criterion should not lead to an exception, but get
// 0 marks.
$response = ['0_0' => 1, '0_1' => 0];
$partscores = $q->grade_parts_that_can_be_graded($response, [], false);
$this->assertEquals(0, $partscores[0]->rawfraction);

// This time the grading criterion can be evaluated.
$response = ['0_0' => 1, '0_1' => 2];
$partscores = $q->grade_parts_that_can_be_graded($response, [], false);
$this->assertEquals(0.5, $partscores[0]->rawfraction);
}

public function test_with_invalidated_grading_criterion() {
$q = $this->get_test_formulas_question('testtwonums');

Expand Down

0 comments on commit ef913f7

Please sign in to comment.