Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / lib / simpletest / testmathslib.php
blob071490dc57e050ea028cb3d25eacd9998f6b695b
1 <?php
3 if (!defined('MOODLE_INTERNAL')) {
4 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
7 require_once($CFG->libdir . '/mathslib.php');
9 /**
10 * Unit tests of mathslib wrapper and underlying EvalMath library.
12 * @author Petr Skoda (skodak)
13 * @version $Id$
15 class mathsslib_test extends UnitTestCase {
17 /**
18 * Tests the basic formula evaluation
20 function test__basic() {
21 $formula = new calc_formula('=1+2');
22 $res = $formula->evaluate();
23 $this->assertEqual($res, 3, '3+1 is: %s');
26 /**
27 * Tests the formula params
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');
35 /**
36 * Tests the changed params
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');
47 /**
48 * Tests the spreadsheet emulation function in formula
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');
56 /**
57 * Tests the min and max functions
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');
68 /**
69 * Tests special chars
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');