mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
MDL-76362 qtype_numerical: Support empty units for apply_units
This commit is contained in:
parent
5f412b3301
commit
12b36d2a32
question/type/numerical
@ -651,9 +651,13 @@ class qtype_numerical_answer_processor {
|
||||
* by the unit multiplier, if any, and the unit string, for reference.
|
||||
*/
|
||||
public function apply_units($response, $separateunit = null) {
|
||||
if ($response === null || trim($response) === '') {
|
||||
return [null, null, null];
|
||||
}
|
||||
|
||||
// Strip spaces (which may be thousands separators) and change other forms
|
||||
// of writing e to e.
|
||||
$response = str_replace(' ', '', $response ?? '');
|
||||
$response = str_replace(' ', '', $response);
|
||||
$response = preg_replace('~(?:e|E|(?:x|\*|×)10(?:\^|\*\*))([+-]?\d+)~', 'e$1', $response);
|
||||
|
||||
// If a . is present or there are multiple , (i.e. 2,456,789 ) assume ,
|
||||
|
@ -62,7 +62,7 @@ class answerprocessor_test extends \advanced_testcase {
|
||||
|
||||
$rc = new \ReflectionClass($ap);
|
||||
$rcm = $rc->getMethod('parse_response');
|
||||
$rcm->setAccessible(True);
|
||||
$rcm->setAccessible(true);
|
||||
|
||||
$this->assertEquals($expected, $rcm->invoke($ap, $args));
|
||||
}
|
||||
@ -200,6 +200,9 @@ class answerprocessor_test extends \advanced_testcase {
|
||||
|
||||
[1, 'frogs', null, '1 frogs'],
|
||||
[null, null, null, '. m/s'],
|
||||
[null, null, null, null],
|
||||
[null, null, null, ''],
|
||||
[null, null, null, ' '],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user