From 11816b9e41f182a042dcb0d7c1416a27c06d92c7 Mon Sep 17 00:00:00 2001 From: Tony Butler Date: Wed, 17 Feb 2016 11:23:22 +0000 Subject: [PATCH] MDL-53137 qtype_numerical: Swap geo tolerance limits for -ve answers --- question/type/numerical/question.php | 3 +++ question/type/numerical/tests/answer_test.php | 10 ++++++++++ 2 files changed, 13 insertions(+) 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)); } }