diff --git a/question/type/numerical/question.php b/question/type/numerical/question.php index db69bdf503e..3acdfe44a31 100644 --- a/question/type/numerical/question.php +++ b/question/type/numerical/question.php @@ -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: diff --git a/question/type/numerical/tests/answer_test.php b/question/type/numerical/tests/answer_test.php index 6aad7d975d6..10e2c261006 100644 --- a/question/type/numerical/tests/answer_test.php +++ b/question/type/numerical/tests/answer_test.php @@ -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)); } }