Permalink
Browse files

NOBUG added floor, ceil and round to evalmath.class.php and added

tests.
  • Loading branch information...
1 parent 950dc91 commit f271a66776691e6ca3a827d47f942f31c377b1a0 @jamiepratt jamiepratt committed with timhunt May 9, 2011
Showing with 61 additions and 1 deletion.
  1. +1 −1 lib/evalmath/evalmath.class.php
  2. +1 −0 lib/evalmath/readme_moodle.txt
  3. +59 −0 lib/simpletest/testmathslib.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');
+ 'sqrt','abs','ln','log','exp','floor','ceil','round');
var $fc = array( // calc functions emulation
'average'=>array(-1), 'max'=>array(-1), 'min'=>array(-1),
@@ -10,6 +10,7 @@ Our changes:
* moved pattern for func and var names into a static var
* made a function to test a string to see if it is a valid func or var name.
* localized strings
+* added round, ceil and floor functions.
To see all changes diff against version 1.1, available from:
http://www.phpclasses.org/browse/package/2695.html
@@ -121,6 +121,65 @@ function test__error_handling() {
}
+ function test_rounding_function() {
+ $formula = new calc_formula('=round(2.5)');
+ $this->assertEqual($formula->evaluate(), 3);
+
+ $formula = new calc_formula('=round(1.5)');
+ $this->assertEqual($formula->evaluate(), 2);
+
+ $formula = new calc_formula('=round(-1.49)');
+ $this->assertEqual($formula->evaluate(), -1);
+
+ $formula = new calc_formula('=round(-2.49)');
+ $this->assertEqual($formula->evaluate(), -2);
+
+ $formula = new calc_formula('=round(-1.5)');
+ $this->assertEqual($formula->evaluate(), -2);
+
+ $formula = new calc_formula('=round(-2.5)');
+ $this->assertEqual($formula->evaluate(), -3);
+
+
+ $formula = new calc_formula('=ceil(2.5)');
+ $this->assertEqual($formula->evaluate(), 3);
+
+ $formula = new calc_formula('=ceil(1.5)');
+ $this->assertEqual($formula->evaluate(), 2);
+
+ $formula = new calc_formula('=ceil(-1.49)');
+ $this->assertEqual($formula->evaluate(), -1);
+
+ $formula = new calc_formula('=ceil(-2.49)');
+ $this->assertEqual($formula->evaluate(), -2);
+
+ $formula = new calc_formula('=ceil(-1.5)');
+ $this->assertEqual($formula->evaluate(), -1);
+
+ $formula = new calc_formula('=ceil(-2.5)');
+ $this->assertEqual($formula->evaluate(), -2);
+
+
+ $formula = new calc_formula('=floor(2.5)');
+ $this->assertEqual($formula->evaluate(), 2);
+
+ $formula = new calc_formula('=floor(1.5)');
+ $this->assertEqual($formula->evaluate(), 1);
+
+ $formula = new calc_formula('=floor(-1.49)');
+ $this->assertEqual($formula->evaluate(), -2);
+
+ $formula = new calc_formula('=floor(-2.49)');
+ $this->assertEqual($formula->evaluate(), -3);
+
+ $formula = new calc_formula('=floor(-1.5)');
+ $this->assertEqual($formula->evaluate(), -2);
+
+ $formula = new calc_formula('=floor(-2.5)');
+ $this->assertEqual($formula->evaluate(), -3);
+
+ }
+
}

0 comments on commit f271a66

Please sign in to comment.