| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php 2 3 if (!defined('MOODLE_INTERNAL')) { 4 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page 5 } 6 7 require_once($CFG->libdir . '/mathslib.php'); 8 9 /** 10 * Unit tests of mathslib wrapper and underlying EvalMath library. 11 * 12 * @author Petr Skoda (skodak) 13 * @version $Id: testmathslib.php,v 1.6 2007/06/18 13:43:40 skodak Exp $ 14 */ 15 class mathsslib_test extends UnitTestCase { 16 17 /** 18 * Tests the basic formula evaluation 19 */ 20 function test__basic() { 21 $formula = new calc_formula('=1+2'); 22 $res = $formula->evaluate(); 23 $this->assertEqual($res, 3, '3+1 is: %s'); 24 } 25 26 /** 27 * Tests the formula params 28 */ 29 function test__params() { 30 $formula = new calc_formula('=a+b+c', array('a'=>10,'b'=>20,'c'=>30)); 31 $res = $formula->evaluate(); 32 $this->assertEqual($res, 60, '10+20+30 is: %s'); 33 } 34 35 /** 36 * Tests the changed params 37 */ 38 function test__changing_params() { 39 $formula = new calc_formula('=a+b+c', array('a'=>10,'b'=>20,'c'=>30)); 40 $res = $formula->evaluate(); 41 $this->assertEqual($res, 60, '10+20+30 is: %s'); 42 $formula->set_params(array('a'=>1,'b'=>2,'c'=>3)); 43 $res = $formula->evaluate(); 44 $this->assertEqual($res, 6, 'changed params 1+2+3 is: %s'); 45 } 46 47 /** 48 * Tests the spreadsheet emulation function in formula 49 */ 50 function test__calc_function() { 51 $formula = new calc_formula('=sum(a,b,c)', array('a'=>10,'b'=>20,'c'=>30)); 52 $res = $formula->evaluate(); 53 $this->assertEqual($res, 60, 'sum(a,b,c) is: %s'); 54 } 55 56 /** 57 * Tests the min and max functions 58 */ 59 function test__minmax_function() { 60 $formula = new calc_formula('=min(a,b,c)', array('a'=>10,'b'=>20,'c'=>30)); 61 $res = $formula->evaluate(); 62 $this->assertEqual($res, 10, 'minimum is: %s'); 63 $formula = new calc_formula('=max(a,b,c)', array('a'=>10,'b'=>20,'c'=>30)); 64 $res = $formula->evaluate(); 65 $this->assertEqual($res, 30, 'maximum is: %s'); 66 } 67 68 /** 69 * Tests special chars 70 */ 71 function test__specialchars() { 72 $formula = new calc_formula('=gi1 + gi2 + gi11', array('gi1'=>10,'gi2'=>20,'gi11'=>30)); 73 $res = $formula->evaluate(); 74 $this->assertEqual($res, 60, 'sum is: %s'); 75 } 76 77 } 78 79 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |