MDL-53137 qtype_numerical: Swap geo tolerance limits for -ve answers

This commit is contained in:
Tony Butler 2016-02-17 11:23:22 +00:00
parent 178aa05227
commit 11816b9e41
No known key found for this signature in database
GPG Key ID: 9711182AA2B802C4
2 changed files with 13 additions and 0 deletions

View File

@ -384,6 +384,9 @@ class qtype_numerical_answer extends question_answer {
case 3: case 'geometric':
$quotient = 1 + abs($tolerance);
if ($this->answer < 0) {
return array($this->answer * $quotient, $this->answer / $quotient);
}
return array($this->answer / $quotient, $this->answer * $quotient);
default:

View File

@ -105,5 +105,15 @@ class answer_test extends \advanced_testcase {
$this->assertTrue($answer->within_tolerance(7));
$this->assertTrue($answer->within_tolerance(14));
$this->assertFalse($answer->within_tolerance(14.01));
// Geometric tolerance, negative answer.
$answer = new qtype_numerical_answer(13, -7.0, 1.0, '', FORMAT_MOODLE, 1.0);
$answer->tolerancetype = 3;
$this->assertFalse($answer->within_tolerance(-3.49));
$this->assertTrue($answer->within_tolerance(-3.5));
$this->assertTrue($answer->within_tolerance(-7));
$this->assertTrue($answer->within_tolerance(-14));
$this->assertFalse($answer->within_tolerance(-14.01));
}
}