diff options
-rw-r--r-- | edit_algebra_form.php | 1 | ||||
-rw-r--r-- | lang/en/qtype_algebra.php | 2 | ||||
-rw-r--r-- | parser.php | 4 | ||||
-rw-r--r-- | question.php | 4 | ||||
-rw-r--r-- | questiontype.php | 5 | ||||
-rw-r--r-- | tests/behat/add.feature | 6 | ||||
-rw-r--r-- | tests/behat/backup_and_restore.feature | 44 | ||||
-rw-r--r-- | tests/behat/edit.feature | 56 | ||||
-rw-r--r-- | tests/behat/export.feature | 35 | ||||
-rw-r--r-- | tests/behat/preview.feature | 55 | ||||
-rw-r--r-- | tests/helper.php | 7 | ||||
-rw-r--r-- | tests/questiontype_test.php | 3 |
12 files changed, 200 insertions, 22 deletions
diff --git a/edit_algebra_form.php b/edit_algebra_form.php index d7d6b85..e091418 100644 --- a/edit_algebra_form.php +++ b/edit_algebra_form.php @@ -260,6 +260,7 @@ class qtype_algebra_edit_form extends question_edit_form { * @param $files some files - I don't know what this is for! - files defined in the form?? */ public function validation($data, $files) { + // Call the base class validation method and keep any errors it generates. $errors = parent::validation($data, $files); diff --git a/lang/en/qtype_algebra.php b/lang/en/qtype_algebra.php index b754965..7760584 100644 --- a/lang/en/qtype_algebra.php +++ b/lang/en/qtype_algebra.php @@ -98,7 +98,7 @@ $string['displayresponse'] = 'Display response'; $string['duplicatevar'] = 'Duplicated variable name: \'{$a}\' is already defined.'; $string['editingalgebra'] = 'Editing an Algebra question'; $string['evalchecks'] = 'Evaluation Checks'; -$string['filloutoneanswer'] = 'You must provide at least one possible answer. Answers left blank will not be used. \'*\' can be used as a wildcard to match any characters. The first matching answer will be used to determine the score and feedback. Only variables defined above are allowed'; +$string['filloutoneanswer'] = 'You must provide at least one possible answer. Answers left blank will not be used. The first matching answer will be used to determine the score and feedback. Only variables defined above are allowed'; $string['filloutonevariable'] = 'You must provide at least one variable.'; $string['illegalvarname'] = 'Illegal variable name \'{$a}\': same name as a parser function or special constant.'; $string['nchecks'] = 'Number of Evaluation Checks'; @@ -1691,7 +1691,7 @@ class qtype_algebra_parser { $i++; continue; } else { - throw new Exception(get_string('missingonearg', 'qtype_algebra', $op)); + throw new Exception(get_string('missingonearg', 'qtype_algebra', $tree[$i]->_value)); } } else if ($tree[$i]->n_args() == 2) { if ($i > 0 and $i < (count($tree) - 1)) { @@ -1701,7 +1701,7 @@ class qtype_algebra_parser { array_splice($tree, $i - 1, 1); continue; } else { - throw new Exception(get_string('missingtwoargs', 'qtype_algebra', $op)); + throw new Exception(get_string('missingtwoargs', 'qtype_algebra', $tree[$i]->_value)); } } } else { diff --git a/question.php b/question.php index bfff2fa..52f8392 100644 --- a/question.php +++ b/question.php @@ -184,10 +184,6 @@ class qtype_algebra_question extends question_graded_by_strategy } public function compare_response_with_answer(array $response, question_answer $answer) { - // Deal with the match anything answer by returning true. - if ($answer->answer == '*') { - return true; - } $expr = $this->parse_expression($response['answer']); // Check that there is a response and if not return false. We do this here // because even an empty response should match a widlcard answer. diff --git a/questiontype.php b/questiontype.php index d2d283d..01f86c4 100644 --- a/questiontype.php +++ b/questiontype.php @@ -513,11 +513,6 @@ class qtype_algebra extends question_type { } public function get_random_guess_score($questiondata) { - foreach ($questiondata->options->answers as $aid => $answer) { - if ('*' == trim($answer->answer)) { - return $answer->fraction; - } - } return 0; } diff --git a/tests/behat/add.feature b/tests/behat/add.feature index 4b7319f..f72399e 100644 --- a/tests/behat/add.feature +++ b/tests/behat/add.feature @@ -30,7 +30,7 @@ Feature: Test creating an Algebra question | id_answer_0 | 2*x | | id_fraction_0 | 100% | | id_feedback_0 | Well done. 2*x is correct. | - | id_answer_1 | * | - | id_fraction_1 | None | - | id_feedback_1 | Your answer is incorrect. | + | id_answer_1 | x | + | id_fraction_1 | 20% | + | id_feedback_1 | It seems that you forgot something. | Then I should see "algebra-001" diff --git a/tests/behat/backup_and_restore.feature b/tests/behat/backup_and_restore.feature new file mode 100644 index 0000000..2122cdf --- /dev/null +++ b/tests/behat/backup_and_restore.feature @@ -0,0 +1,44 @@ +@qtype @qtype_algebra +Feature: Test duplicating a quiz containing an Algebra question + As a teacher + In order re-use my courses containing Algebra questions + I need to be able to backup and restore them + + Background: + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "question categories" exist: + | contextlevel | reference | name | + | Course | C1 | Test questions | + And the following "questions" exist: + | questioncategory | qtype | name | template | + | Test questions | algebra | Algebra question | simplemath | + And the following "activities" exist: + | activity | name | course | idnumber | + | quiz | Test quiz | C1 | quiz1 | + And quiz "Test quiz" contains the following questions: + | Algebra question | 1 | + And I log in as "admin" + And I am on "Course 1" course homepage + + @javascript + Scenario: Backup and restore a course containing an algebra question + When I backup "Course 1" course using this options: + | Confirmation | Filename | test_backup.mbz | + And I restore "test_backup.mbz" backup into a new course using this options: + | Schema | Course name | Course 2 | + And I navigate to "Question bank" node in "Course administration" + And I click on "Edit" "link" in the "Algebra question" "table_row" + Then the following fields match these values: + | Question name | Algebra question | + | Question text | P(x) = 3x and Q(x) = 4x. Calculate (P + Q)(x) | + | General feedback | Generalfeedback: (P + Q)(x) = 7x. | + | Default mark | 1 | + | id_variable_0 | x | + | id_varmin_0 | -5 | + | id_varmax_0 | 5 | + | id_answer_0 | 7*x | + | id_fraction_0 | 100% | + | id_feedback_0 | This is a very good answer. | + diff --git a/tests/behat/edit.feature b/tests/behat/edit.feature new file mode 100644 index 0000000..87a2a54 --- /dev/null +++ b/tests/behat/edit.feature @@ -0,0 +1,56 @@ +@qtype @qtype_algebra +Feature: Test editing an Algebra question + As a teacher + In order to be able to update my Algebra question + I need to edit them + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | T1 | Teacher1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + And the following "question categories" exist: + | contextlevel | reference | name | + | Course | C1 | Test questions | + And the following "questions" exist: + | questioncategory | qtype | name | template | + | Test questions | algebra | algebra-001 for editing | simplemath | + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "Question bank" node in "Course administration" + + @javascript @_switch_window + Scenario: Edit an Algebra question + When I click on "Edit" "link" in the "algebra-001 for editing" "table_row" + And I set the following fields to these values: + | Question name | | + And I press "id_submitbutton" + Then I should see "You must supply a value here." + When I set the following fields to these values: + | Question name | Edited algebra-001 name | + And I press "id_submitbutton" + Then I should see "Edited algebra-001 name" + When I click on "Edit" "link" in the "Edited algebra-001 name" "table_row" + And I set the following fields to these values: + | id_answer_1 | 6*x | + | id_fraction_1 | 10% | + | id_feedback_1 | 3x + 4x gives 7x not 6x. | + And I press "id_submitbutton" + Then I should see "Edited algebra-001 name" + When I click on "Preview" "link" in the "Edited algebra-001 name" "table_row" + And I switch to "questionpreview" window + Then I should see "P(x) = 3x and Q(x) = 4x. Calculate (P + Q)(x)" + # Set behaviour options + And I set the following fields to these values: + | behaviour | immediatefeedback | + And I press "Start again with these options" + And I set the field with xpath "//div[@class='qtext']//input[contains(@id, '1_answer')]" to "6*x" + And I press "Check" + Then I should see "3x + 4x gives 7x not 6x." + And I should see "Generalfeedback: (P + Q)(x) = 7x." + And I should see "The correct answer is: 7*x" diff --git a/tests/behat/export.feature b/tests/behat/export.feature new file mode 100644 index 0000000..8c92943 --- /dev/null +++ b/tests/behat/export.feature @@ -0,0 +1,35 @@ +@qtype @qtype_algebra +Feature: Test exporting Short answer questions + As a teacher + In order to be able to reuse my Algebra questions + I need to export them + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | T1 | Teacher1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + And the following "question categories" exist: + | contextlevel | reference | name | + | Course | C1 | Test questions | + And the following "questions" exist: + | questioncategory | qtype | name | template | + | Test questions | algebra | algebra-001 | simplemath | + And I log in as "teacher1" + And I am on "Course 1" course homepage + + Scenario: Export an Algebra question + When I navigate to "Export" node in "Course administration > Question bank" + And I set the field "id_format_xml" to "1" + And I press "Export questions to file" + Then following "click here" should download between "1200" and "1300" bytes + # If the download step is the last in the scenario then we can sometimes run + # into the situation where the download page causes a http redirect but behat + # has already conducted its reset (generating an error). By putting a logout + # step we avoid behat doing the reset until we are off that page. + And I log out diff --git a/tests/behat/preview.feature b/tests/behat/preview.feature new file mode 100644 index 0000000..6b06db8 --- /dev/null +++ b/tests/behat/preview.feature @@ -0,0 +1,55 @@ +@qtype @qtype_algebra +Feature: Preview a Short answer question + As a teacher + In order to check my Short answer questions will work for students + I need to preview them + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | T1 | Teacher1 | teacher1@moodle.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + And the following "question categories" exist: + | contextlevel | reference | name | + | Course | C1 | Test questions | + And the following "questions" exist: + | questioncategory | qtype | name | template | + | Test questions | algebra | algebra-001 | simplemath | + Given I log in as "teacher1" + And I am on "Course 1" course homepage + And I navigate to "Question bank" node in "Course administration" + + @javascript @_switch_window + Scenario: Preview an Algebra question with correct answer + When I click on "Preview" "link" in the "algebra-001" "table_row" + And I switch to "questionpreview" window + Then I should see "P(x) = 3x and Q(x) = 4x. Calculate (P + Q)(x)" + # Set behaviour options + And I set the following fields to these values: + | behaviour | immediatefeedback | + And I press "Start again with these options" + And I set the field with xpath "//div[@class='qtext']//input[contains(@id, '1_answer')]" to "7*x" + And I press "Check" + Then I should see "This is a very good answer." + And I should see "Generalfeedback: (P + Q)(x) = 7x." + And I should see "The correct answer is: 7*x" + + @javascript @_switch_window + Scenario: Preview an Algebra question with incorrect answer + When I click on "Preview" "link" in the "algebra-001" "table_row" + And I switch to "questionpreview" window + Then I should see "P(x) = 3x and Q(x) = 4x. Calculate (P + Q)(x)" + # Set behaviour options + And I set the following fields to these values: + | behaviour | immediatefeedback | + And I press "Start again with these options" + And I set the field with xpath "//div[@class='qtext']//input[contains(@id, '1_answer')]" to "6*x" + And I press "Check" + Then I should see "That is a bad answer." + And I should see "Generalfeedback: (P + Q)(x) = 7x." + And I should see "The correct answer is: 7*x"
\ No newline at end of file diff --git a/tests/helper.php b/tests/helper.php index 5af6a9b..e0f0381 100644 --- a/tests/helper.php +++ b/tests/helper.php @@ -55,7 +55,6 @@ class qtype_algebra_test_helper extends question_test_helper { $q->answerprefix = ''; $q->answers = array( 13 => new question_answer(13, '7*x', 1.0, 'This is a very good answer.', FORMAT_HTML), - 14 => new question_answer(14, '*', 0.0, 'This is completely wrong.', FORMAT_HTML), ); $q->variables = array( 7 => new qtype_algebra_variable(7, 'x', -5, 5) @@ -88,7 +87,6 @@ class qtype_algebra_test_helper extends question_test_helper { $qdata->options->answerprefix = ''; $qdata->options->answers = array( 13 => new question_answer(13, '7*x', 1.0, 'This is a very good answer.', FORMAT_HTML), - 14 => new question_answer(14, '*', 0.0, 'This is completely wrong.', FORMAT_HTML), ); $qdata->options->variables = array( 7 => new qtype_algebra_variable(7, 'x', -5, 5) @@ -116,14 +114,13 @@ class qtype_algebra_test_helper extends question_test_helper { $form->allowedfuncs = array('all' => 1); $form->disallow = ''; $form->answerprefix = ''; - $form->answer = array('7*x', '*'); - $form->fraction = array('1.0', '0.0'); + $form->answer = array('7*x'); + $form->fraction = array('1.0'); $form->variable = array('x'); $form->varmin = array('-5'); $form->varmax = array('5'); $form->feedback = array( array('text' => 'This is a very good answer.', 'format' => FORMAT_HTML), - array('text' => 'This is completely wrong.', 'format' => FORMAT_HTML), ); $form->penalty = 0.3333333; diff --git a/tests/questiontype_test.php b/tests/questiontype_test.php index bd53a47..ee19d6b 100644 --- a/tests/questiontype_test.php +++ b/tests/questiontype_test.php @@ -68,8 +68,7 @@ class qtype_algebra_test extends advanced_testcase { public function test_get_random_guess_score() { $q = test_question_maker::get_question_data('algebra'); - $q->options->answers[14]->fraction = 0.1; - $this->assertEquals(0.1, $this->qtype->get_random_guess_score($q)); + $this->assertEquals(0, $this->qtype->get_random_guess_score($q)); } public function test_get_possible_responses() { |