ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilMathBaseAdapterTest Class Reference
+ Inheritance diagram for ilMathBaseAdapterTest:
+ Collaboration diagram for ilMathBaseAdapterTest:

Public Member Functions

 testAdd ($a, $b, $result, $scale)
 addData More...
 
 testSub ($a, $b, $result, $scale)
 subData More...
 
 testMul ($a, $b, $result, $scale)
 mulData More...
 
 testDiv ($a, $b, $result, $scale)
 divData More...
 
 testSqrt ($a, $result, $scale)
 sqrtData More...
 
 testPow ($a, $b, $result, $scale)
 powData More...
 
 testMod ($a, $b, $result)
 modData More...
 
 testEquals ($a, $b, $result, $scale)
 equalsData More...
 
 testCalculation ($formula, $result, $scale)
 calcData More...
 
 testDivisionsByZero ()
 
 testModuloByZero ()
 
 addData ()
 
 subData ()
 
 mulData ()
 
 divData ()
 
 modData ()
 
 sqrtData ()
 
 powData ()
 
 equalsData ()
 
 calcData ()
 

Data Fields

const DEFAULT_SCALE = 50
 

Protected Member Functions

 setUp ()
 

Protected Attributes

 $mathAdapter
 
 $evalMath
 

Private Member Functions

 assertEqualNumbers (string $actual, string $expected)
 This method is used as a 'Comparator' for two numeric strings and is equal to the ScalarComparator behaviour of PHPUnit 5.x In PHPUnit 8 the ScalarComparators uses a strict string comparison, so numbers with a different amount of trailing 0 decimals are not equal anymore. More...
 

Detailed Description

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

Definition at line 12 of file ilMathBaseAdapterTest.php.

Member Function Documentation

◆ addData()

ilMathBaseAdapterTest::addData ( )
Returns
array

Definition at line 149 of file ilMathBaseAdapterTest.php.

150  {
151  return [
152  ['1', '2', '3', self::DEFAULT_SCALE]
153  ];
154  }

◆ assertEqualNumbers()

ilMathBaseAdapterTest::assertEqualNumbers ( string  $actual,
string  $expected 
)
private

This method is used as a 'Comparator' for two numeric strings and is equal to the ScalarComparator behaviour of PHPUnit 5.x In PHPUnit 8 the ScalarComparators uses a strict string comparison, so numbers with a different amount of trailing 0 decimals are not equal anymore.

See also
Parameters
string$actual
string$expected

Definition at line 47 of file ilMathBaseAdapterTest.php.

Referenced by testAdd(), testCalculation(), testDiv(), testEquals(), testMod(), testMul(), testPow(), testSqrt(), and testSub().

48  {
49  $differ = new Differ(new UnifiedDiffOutputBuilder("\n--- Expected\n+++ Actual\n"));
50 
51  $this->assertTrue($actual == $expected, $differ->diff($actual, $expected));
52  }
+ Here is the caller graph for this function:

◆ calcData()

ilMathBaseAdapterTest::calcData ( )

Definition at line 235 of file ilMathBaseAdapterTest.php.

236  {
237  return [
238  ['3+5', '8', self::DEFAULT_SCALE],
239  ['-3+5', '2', self::DEFAULT_SCALE],
240  ['3*6+5', '23', self::DEFAULT_SCALE],
241  ['10/2', '5', self::DEFAULT_SCALE],
242  ['13/60', '0.2166666666666', 13],
243  ['(-(-8)-sqrt((-8)^2-4*(7)))/(2)', '1', self::DEFAULT_SCALE],
244  ['(-(-8)+sqrt((-8)^2-4*(7)))/(2)', '7', self::DEFAULT_SCALE],
245  ['(-(-41)-sqrt((-41)^2-4*(1)*(5)))/(2*(1))', '0.122', 3],
246  ['(-(-41)+sqrt((-41)^2-4*(1)*(5)))/(2*(1))', '40.877', 3],
247  ['4^2-2*4+0.5*-16', '0', self::DEFAULT_SCALE],
248  ['-2^2-2*-2+0.5*-16', '-8', self::DEFAULT_SCALE]
249  ];
250  }

◆ divData()

ilMathBaseAdapterTest::divData ( )
Returns
array

Definition at line 180 of file ilMathBaseAdapterTest.php.

181  {
182  return [
183  ['1', '2', '0.5', self::DEFAULT_SCALE],
184  ['', '2', '0', self::DEFAULT_SCALE],
185  ];
186  }

◆ equalsData()

ilMathBaseAdapterTest::equalsData ( )
Returns
array

Definition at line 224 of file ilMathBaseAdapterTest.php.

225  {
226  return [
227  ['3', '3', true, null],
228  ['27.424', '27.424', true, 5]
229  ];
230  }

◆ modData()

ilMathBaseAdapterTest::modData ( )
Returns
array

Definition at line 191 of file ilMathBaseAdapterTest.php.

192  {
193  return [
194  ['1', '2', '1']
195  ];
196  }

◆ mulData()

ilMathBaseAdapterTest::mulData ( )
Returns
array

Definition at line 169 of file ilMathBaseAdapterTest.php.

170  {
171  return [
172  ['1', '2', '2', self::DEFAULT_SCALE],
173  ['1', '', '0', self::DEFAULT_SCALE]
174  ];
175  }

◆ powData()

ilMathBaseAdapterTest::powData ( )
Returns
array

Definition at line 214 of file ilMathBaseAdapterTest.php.

215  {
216  return [
217  ['3', '2', '9', self::DEFAULT_SCALE]
218  ];
219  }

◆ setUp()

ilMathBaseAdapterTest::setUp ( )
protected

Definition at line 29 of file ilMathBaseAdapterTest.php.

References ilMath\setDefaultAdapter().

29  : void
30  {
31  require_once 'Services/Math/classes/class.ilMath.php';
32  require_once 'Services/Math/classes/class.EvalMath.php';
33 
34  ilMath::setDefaultAdapter($this->mathAdapter);
35  $this->evalMath = new EvalMath();
36  parent::setUp();
37  }
static setDefaultAdapter(ilMathAdapter $adapter)
+ Here is the call graph for this function:

◆ sqrtData()

ilMathBaseAdapterTest::sqrtData ( )
Returns
array

Definition at line 201 of file ilMathBaseAdapterTest.php.

202  {
203  return [
204  ['9', '3', self::DEFAULT_SCALE],
205  ['4294967296', '65536', self::DEFAULT_SCALE],
206  ['12345678901234567890', '3513641828', null],
207  ['12345678901234567890', '3513641828.82', 2]
208  ];
209  }

◆ subData()

ilMathBaseAdapterTest::subData ( )
Returns
array

Definition at line 159 of file ilMathBaseAdapterTest.php.

160  {
161  return [
162  ['1', '2', '-1', self::DEFAULT_SCALE]
163  ];
164  }

◆ testAdd()

ilMathBaseAdapterTest::testAdd (   $a,
  $b,
  $result,
  $scale 
)

addData

Definition at line 57 of file ilMathBaseAdapterTest.php.

References Vendor\Package\$a, Vendor\Package\$b, $result, and assertEqualNumbers().

58  {
59  $this->assertEqualNumbers($result, $this->mathAdapter->add($a, $b, $scale));
60  }
$result
assertEqualNumbers(string $actual, string $expected)
This method is used as a 'Comparator' for two numeric strings and is equal to the ScalarComparator be...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:

◆ testCalculation()

ilMathBaseAdapterTest::testCalculation (   $formula,
  $result,
  $scale 
)

calcData

Definition at line 121 of file ilMathBaseAdapterTest.php.

References $result, and assertEqualNumbers().

122  {
123  $this->assertEqualNumbers($result, ilMath::_applyScale($this->evalMath->evaluate($formula), $scale));
124  }
$result
assertEqualNumbers(string $actual, string $expected)
This method is used as a 'Comparator' for two numeric strings and is equal to the ScalarComparator be...
+ Here is the call graph for this function:

◆ testDiv()

ilMathBaseAdapterTest::testDiv (   $a,
  $b,
  $result,
  $scale 
)

divData

Definition at line 81 of file ilMathBaseAdapterTest.php.

References Vendor\Package\$a, Vendor\Package\$b, $result, and assertEqualNumbers().

82  {
83  $this->assertEqualNumbers($result, $this->mathAdapter->div($a, $b, $scale));
84  }
$result
assertEqualNumbers(string $actual, string $expected)
This method is used as a 'Comparator' for two numeric strings and is equal to the ScalarComparator be...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:

◆ testDivisionsByZero()

ilMathBaseAdapterTest::testDivisionsByZero ( )

Definition at line 129 of file ilMathBaseAdapterTest.php.

130  {
131  $this->expectException(ilMathDivisionByZeroException::class);
132 
133  $this->mathAdapter->div(1, 0);
134  }

◆ testEquals()

ilMathBaseAdapterTest::testEquals (   $a,
  $b,
  $result,
  $scale 
)

equalsData

Definition at line 113 of file ilMathBaseAdapterTest.php.

References Vendor\Package\$a, Vendor\Package\$b, $result, and assertEqualNumbers().

114  {
115  $this->assertEqualNumbers($result, $this->mathAdapter->equals($a, $b, $scale));
116  }
$result
assertEqualNumbers(string $actual, string $expected)
This method is used as a 'Comparator' for two numeric strings and is equal to the ScalarComparator be...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:

◆ testMod()

ilMathBaseAdapterTest::testMod (   $a,
  $b,
  $result 
)

modData

Definition at line 105 of file ilMathBaseAdapterTest.php.

References Vendor\Package\$a, Vendor\Package\$b, $result, and assertEqualNumbers().

106  {
107  $this->assertEqualNumbers($result, $this->mathAdapter->mod($a, $b));
108  }
$result
assertEqualNumbers(string $actual, string $expected)
This method is used as a 'Comparator' for two numeric strings and is equal to the ScalarComparator be...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:

◆ testModuloByZero()

ilMathBaseAdapterTest::testModuloByZero ( )

Definition at line 139 of file ilMathBaseAdapterTest.php.

140  {
141  $this->expectException(ilMathDivisionByZeroException::class);
142 
143  $this->mathAdapter->mod(1, 0);
144  }

◆ testMul()

ilMathBaseAdapterTest::testMul (   $a,
  $b,
  $result,
  $scale 
)

mulData

Definition at line 73 of file ilMathBaseAdapterTest.php.

References Vendor\Package\$a, Vendor\Package\$b, $result, and assertEqualNumbers().

74  {
75  $this->assertEqualNumbers($result, $this->mathAdapter->mul($a, $b, $scale));
76  }
$result
assertEqualNumbers(string $actual, string $expected)
This method is used as a 'Comparator' for two numeric strings and is equal to the ScalarComparator be...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:

◆ testPow()

ilMathBaseAdapterTest::testPow (   $a,
  $b,
  $result,
  $scale 
)

powData

Definition at line 97 of file ilMathBaseAdapterTest.php.

References Vendor\Package\$a, Vendor\Package\$b, $result, and assertEqualNumbers().

98  {
99  $this->assertEqualNumbers($result, $this->mathAdapter->pow($a, $b, $scale));
100  }
$result
assertEqualNumbers(string $actual, string $expected)
This method is used as a 'Comparator' for two numeric strings and is equal to the ScalarComparator be...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:

◆ testSqrt()

ilMathBaseAdapterTest::testSqrt (   $a,
  $result,
  $scale 
)

sqrtData

Definition at line 89 of file ilMathBaseAdapterTest.php.

References Vendor\Package\$a, $result, and assertEqualNumbers().

90  {
91  $this->assertEqualNumbers($result, $this->mathAdapter->sqrt($a, $scale));
92  }
$result
assertEqualNumbers(string $actual, string $expected)
This method is used as a 'Comparator' for two numeric strings and is equal to the ScalarComparator be...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:

◆ testSub()

ilMathBaseAdapterTest::testSub (   $a,
  $b,
  $result,
  $scale 
)

subData

Definition at line 65 of file ilMathBaseAdapterTest.php.

References Vendor\Package\$a, Vendor\Package\$b, $result, and assertEqualNumbers().

66  {
67  $this->assertEqualNumbers($result, $this->mathAdapter->sub($a, $b, $scale));
68  }
$result
assertEqualNumbers(string $actual, string $expected)
This method is used as a 'Comparator' for two numeric strings and is equal to the ScalarComparator be...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:

Field Documentation

◆ $evalMath

ilMathBaseAdapterTest::$evalMath
protected

Definition at line 24 of file ilMathBaseAdapterTest.php.

◆ $mathAdapter

ilMathBaseAdapterTest::$mathAdapter
protected

Definition at line 19 of file ilMathBaseAdapterTest.php.

◆ DEFAULT_SCALE

const ilMathBaseAdapterTest::DEFAULT_SCALE = 50

Definition at line 14 of file ilMathBaseAdapterTest.php.


The documentation for this class was generated from the following file: