Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-29173 grade: altered the definiton of round() and added some more…

… unit tests
  • Loading branch information...
commit db5e62d25070afd3da81a947a1ec100bb49259c9 1 parent 14fdcb4
@andyjdavis andyjdavis authored
View
2  lib/evalmath/evalmath.class.php
@@ -107,7 +107,7 @@ class EvalMath {
'sin','sinh','arcsin','asin','arcsinh','asinh',
'cos','cosh','arccos','acos','arccosh','acosh',
'tan','tanh','arctan','atan','arctanh','atanh',
- 'sqrt','abs','ln','log','exp','floor','ceil','round');
+ 'sqrt','abs','ln','log','exp','floor','ceil');
var $fc = array( // calc functions emulation
'average'=>array(-1), 'max'=>array(-1), 'min'=>array(-1),
View
18 lib/simpletest/testmathslib.php
@@ -149,6 +149,10 @@ public function test__error_handling() {
}
public function test_rounding_function() {
+
+ // Rounding to the default number of decimal places
+ // The default == 0
+
$formula = new calc_formula('=round(2.5)');
$this->assertEqual($formula->evaluate(), 3);
@@ -203,6 +207,20 @@ public function test_rounding_function() {
$formula = new calc_formula('=floor(-2.5)');
$this->assertEqual($formula->evaluate(), -3);
+ // Rounding to an explicit number of decimal places
+
+ $formula = new calc_formula('=round(2.5, 1)');
+ $this->assertEqual($formula->evaluate(), 2.5);
+
+ $formula = new calc_formula('=round(2.5, 0)');
+ $this->assertEqual($formula->evaluate(), 3);
+
+ $formula = new calc_formula('=round(1.2345, 2)');
+ $this->assertEqual($formula->evaluate(), 1.23);
+
+ $formula = new calc_formula('=round(123.456, -1)');
+ $this->assertEqual($formula->evaluate(), 120);
+
}
public function test_scientific_notation() {
Please sign in to comment.
Something went wrong with that request. Please try again.