Skip to content

Commit dfce95c

Browse files
committed
feedback, correct answer, update behat
1 parent 13c9ef5 commit dfce95c

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

classes/local/answer_parser.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,18 @@ public function __construct($tokenlist, array $knownvariables = [], bool $caretm
8585
public function is_acceptable_for_answertype(int $type, bool $acceptempty = false): bool {
8686
// An empty answer is never acceptable regardless of the answer type, unless empty fields
8787
// are explicitly allowed for a question's part.
88+
// FIXME: this can be removed later
8889
if (empty($this->tokenlist)) {
8990
return $acceptempty;
9091
}
92+
$firsttoken = reset($this->tokenlist);
93+
if (count($this->tokenlist) === 1 && $firsttoken->type === token::EMPTY) {
94+
return $acceptempty;
95+
}
96+
if (empty($this->tokenlist)) {
97+
return $acceptempty;
98+
}
99+
91100
if ($type === qtype_formulas::ANSWER_TYPE_NUMBER) {
92101
return $this->is_acceptable_number();
93102
}

lang/en/qtype_formulas.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
$string['defaultwidthunit_desc'] = 'Unit of length used for the default width settings below. The units "em" or "rem" correspond approximately to the width of one digit.';
104104
$string['emptyallowed'] = 'Students may leave one or more fields empty.';
105105
$string['emptyallowed_help'] = 'Check this option for parts where not all fields have to be filled, e. g. when you have two fields for an equation that could have just one solution, and you do not want to give away the number of solutions.';
106+
$string['emptyanswer'] = '[empty]';
106107
$string['error_algebraic_relerr'] = 'Relative error (_relerr) cannot be used with answer type algebraic formula.';
107108
$string['error_algvar_numbers'] = 'Algebraic variables can only be initialized with a list of numbers.';
108109
$string['error_answer_missing'] = 'No answer has been defined.';

question.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ public function check_file_access($qa, $options, $component, $filearea, $args, $
460460
* @return bool whether this response can be graded
461461
*/
462462
public function is_gradable_response(array $response): bool {
463+
if (array_key_exists('_seed', $response)) {
464+
return false;
465+
}
463466
// Iterate over all parts. If at least one part is gradable, we can leave early.
464467
foreach ($this->parts as $part) {
465468
if ($part->is_gradable_response($response)) {
@@ -523,7 +526,7 @@ public function summarise_response(array $response) {
523526
foreach ($this->parts as $part) {
524527
$summary[] = $part->summarise_response($response);
525528
}
526-
return implode(', ', $summary);
529+
return implode('; ', $summary);
527530
}
528531

529532
/**
@@ -1266,6 +1269,9 @@ public function is_complete_response(array $response): bool {
12661269
* @return bool
12671270
*/
12681271
public function is_unanswered(array $response): bool {
1272+
if (array_key_exists('_seed', $response)) {
1273+
return true;
1274+
}
12691275
if (!array_key_exists('normalized', $response)) {
12701276
$response = $this->normalize_response($response);
12711277
}
@@ -1646,8 +1652,12 @@ public function get_correct_response(bool $forfeedback = false): array {
16461652
$answers = $this->get_evaluated_answers();
16471653

16481654
// Numeric answers should be localized, if that functionality is enabled.
1655+
// Empty answers should be just the empty string; a more user-friendly
1656+
// output will be created in the renderer.
16491657
foreach ($answers as &$answer) {
1650-
if (is_numeric($answer)) {
1658+
if ($answer === '$EMPTY') {
1659+
$answer = '';
1660+
} else if (is_numeric($answer)) {
16511661
$answer = qtype_formulas::format_float($answer);
16521662
}
16531663
}

renderer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,11 @@ public function correct_response(question_attempt $qa) {
749749
*/
750750
public function part_correct_response($part) {
751751
$answers = $part->get_correct_response(true);
752+
foreach ($answers as &$answer) {
753+
if ($answer === '') {
754+
$answer = get_string('emptyanswer', 'qtype_formulas');
755+
}
756+
}
752757
$answertext = implode('; ', $answers);
753758

754759
$string = ($part->answernotunique ? 'correctansweris' : 'uniquecorrectansweris');

tests/behat/export.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Feature: Test exporting Formulas questions
2727
When I am on the "Course 1" "core_question > course question export" page
2828
And I set the field "id_format_xml" to "1"
2929
And I press "Export questions to file"
30-
Then following "click here" should download between "6250" and "6500" bytes
30+
Then following "click here" should download between "6400" and "6600" bytes
3131
# If the download step is the last in the scenario then we can sometimes run
3232
# into the situation where the download page causes a http redirect but behat
3333
# has already conducted its reset (generating an error). By putting a logout

0 commit comments

Comments
 (0)