Skip to content

Commit

Permalink
Merge branch 'MDL-29173_calc_21' of git://github.com/andyjdavis/moodl…
Browse files Browse the repository at this point in the history
…e into MOODLE_21_STABLE
  • Loading branch information
danpoltawski committed Jun 4, 2012
2 parents a6dfc10 + 196b3fd commit ca409b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/evalmath/evalmath.class.php
Expand Up @@ -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),
Expand Down
18 changes: 18 additions & 0 deletions lib/simpletest/testmathslib.php
Expand Up @@ -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);

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit ca409b9

Please sign in to comment.