ILIAS  release_8 Revision v8.23
ilMathBaseAdapterTest Class Reference
+ Inheritance diagram for ilMathBaseAdapterTest:
+ Collaboration diagram for ilMathBaseAdapterTest:

Public Member Functions

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

Protected Member Functions

 setUp ()
 

Protected Attributes

const DEFAULT_SCALE = 50
 
ilMathAdapter $mathAdapter
 
EvalMath $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

Definition at line 26 of file ilMathBaseAdapterTest.php.

Member Function Documentation

◆ addData()

ilMathBaseAdapterTest::addData ( )
Returns
array

Definition at line 155 of file ilMathBaseAdapterTest.php.

155  : array
156  {
157  return [
158  ['1', '2', '3', self::DEFAULT_SCALE]
159  ];
160  }

◆ 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

PhpUnitTestsInspection

Definition at line 51 of file ilMathBaseAdapterTest.php.

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

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

◆ calcData()

ilMathBaseAdapterTest::calcData ( )

Definition at line 243 of file ilMathBaseAdapterTest.php.

243  : array
244  {
245  return [
246  ['3+5', '8', self::DEFAULT_SCALE],
247  ['-3+5', '2', self::DEFAULT_SCALE],
248  ['3*6+5', '23', self::DEFAULT_SCALE],
249  ['10/2', '5', self::DEFAULT_SCALE],
250  ['13/60', '0.2166666666666', 13],
251  ['(-(-8)-sqrt((-8)^2-4*(7)))/(2)', '1', self::DEFAULT_SCALE],
252  ['(-(-8)+sqrt((-8)^2-4*(7)))/(2)', '7', self::DEFAULT_SCALE],
253  ['(-(-41)-sqrt((-41)^2-4*(1)*(5)))/(2*(1))', '0.122', 3],
254  ['(-(-41)+sqrt((-41)^2-4*(1)*(5)))/(2*(1))', '40.877', 3],
255  ['4^2-2*4+0.5*-16', '0', self::DEFAULT_SCALE],
256  ['-2^2-2*-2+0.5*-16', '-8', self::DEFAULT_SCALE]
257  ];
258  }

◆ divData()

ilMathBaseAdapterTest::divData ( )
Returns
array

Definition at line 187 of file ilMathBaseAdapterTest.php.

187  : array
188  {
189  return [
190  'Division with integer operands' => ['1', '2', '0.5', self::DEFAULT_SCALE],
191  'Division with empty string operand' => ['', '2', '0', self::DEFAULT_SCALE],
192  'Division with decimal operands' => ['3.75', '2.5', '1.5', self::DEFAULT_SCALE],
193  ];
194  }

◆ equalsData()

ilMathBaseAdapterTest::equalsData ( )
Returns
array

Definition at line 232 of file ilMathBaseAdapterTest.php.

232  : array
233  {
234  return [
235  ['3', '3', true, null],
236  ['27.424', '27.424', true, 5]
237  ];
238  }

◆ modData()

ilMathBaseAdapterTest::modData ( )
Returns
array

Definition at line 199 of file ilMathBaseAdapterTest.php.

199  : array
200  {
201  return [
202  ['1', '2', '1']
203  ];
204  }

◆ mulData()

ilMathBaseAdapterTest::mulData ( )
Returns
array

Definition at line 175 of file ilMathBaseAdapterTest.php.

175  : array
176  {
177  return [
178  'Multiplication with integer operands' => ['1', '2', '2', self::DEFAULT_SCALE],
179  'Multiplication with empty string operand' => ['1', '', '0', self::DEFAULT_SCALE],
180  'Multiplication with decimal operands' => ['1.5', '2.5', '3.75', self::DEFAULT_SCALE]
181  ];
182  }

◆ powData()

ilMathBaseAdapterTest::powData ( )
Returns
array

Definition at line 222 of file ilMathBaseAdapterTest.php.

222  : array
223  {
224  return [
225  ['3', '2', '9', self::DEFAULT_SCALE]
226  ];
227  }

◆ setUp()

ilMathBaseAdapterTest::setUp ( )
protected

Definition at line 36 of file ilMathBaseAdapterTest.php.

References ilMath\setDefaultAdapter().

36  : void
37  {
38  ilMath::setDefaultAdapter($this->mathAdapter);
39  $this->evalMath = new EvalMath();
40  parent::setUp();
41  }
static setDefaultAdapter(ilMathAdapter $adapter)
+ Here is the call graph for this function:

◆ sqrtData()

ilMathBaseAdapterTest::sqrtData ( )
Returns
array

Definition at line 209 of file ilMathBaseAdapterTest.php.

209  : array
210  {
211  return [
212  ['9', '3', self::DEFAULT_SCALE],
213  ['4294967296', '65536', self::DEFAULT_SCALE],
214  ['12345678901234567890', '3513641828', null],
215  ['12345678901234567890', '3513641828.82', 2]
216  ];
217  }

◆ subData()

ilMathBaseAdapterTest::subData ( )
Returns
array

Definition at line 165 of file ilMathBaseAdapterTest.php.

165  : array
166  {
167  return [
168  ['1', '2', '-1', self::DEFAULT_SCALE]
169  ];
170  }

◆ testAdd()

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

addData

Definition at line 62 of file ilMathBaseAdapterTest.php.

References assertEqualNumbers().

62  : void
63  {
64  $this->assertEqualNumbers($result, $this->mathAdapter->add($a, $b, $scale));
65  }
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 ( string  $formula,
string  $result,
int  $scale 
)

calcData

Definition at line 127 of file ilMathBaseAdapterTest.php.

References assertEqualNumbers().

127  : void
128  {
129  $this->assertEqualNumbers($result, ilMath::_applyScale($this->evalMath->evaluate($formula), $scale));
130  }
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 ( string  $a,
string  $b,
string  $result,
int  $scale 
)

divData

Definition at line 86 of file ilMathBaseAdapterTest.php.

References assertEqualNumbers().

86  : void
87  {
88  $this->assertEqualNumbers($result, $this->mathAdapter->div($a, $b, $scale));
89  }
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 135 of file ilMathBaseAdapterTest.php.

135  : void
136  {
137  $this->expectException(ilMathDivisionByZeroException::class);
138 
139  $this->mathAdapter->div(1, 0);
140  }

◆ testEquals()

ilMathBaseAdapterTest::testEquals ( string  $a,
string  $b,
bool  $result,
?int  $scale 
)

equalsData

Definition at line 119 of file ilMathBaseAdapterTest.php.

References assertEqualNumbers().

119  : void
120  {
121  $this->assertEqualNumbers($result, $this->mathAdapter->equals($a, $b, $scale));
122  }
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 ( string  $a,
string  $b,
string  $result 
)

modData

Exceptions
ilMathDivisionByZeroException

Definition at line 111 of file ilMathBaseAdapterTest.php.

References assertEqualNumbers().

111  : void
112  {
113  $this->assertEqualNumbers($result, $this->mathAdapter->mod($a, $b));
114  }
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 145 of file ilMathBaseAdapterTest.php.

145  : void
146  {
147  $this->expectException(ilMathDivisionByZeroException::class);
148 
149  $this->mathAdapter->mod(1, 0);
150  }

◆ testMul()

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

mulData

Definition at line 78 of file ilMathBaseAdapterTest.php.

References assertEqualNumbers().

78  : void
79  {
80  $this->assertEqualNumbers($result, $this->mathAdapter->mul($a, $b, $scale));
81  }
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 ( string  $a,
string  $b,
string  $result,
?int  $scale 
)

powData

Definition at line 102 of file ilMathBaseAdapterTest.php.

References assertEqualNumbers().

102  : void
103  {
104  $this->assertEqualNumbers($result, $this->mathAdapter->pow($a, $b, $scale));
105  }
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 ( string  $a,
string  $result,
?int  $scale 
)

sqrtData

Definition at line 94 of file ilMathBaseAdapterTest.php.

References assertEqualNumbers().

94  : void
95  {
96  $this->assertEqualNumbers($result, $this->mathAdapter->sqrt($a, $scale));
97  }
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 ( string  $a,
string  $b,
string  $result,
int  $scale 
)

subData

Definition at line 70 of file ilMathBaseAdapterTest.php.

References assertEqualNumbers().

70  : void
71  {
72  $this->assertEqualNumbers($result, $this->mathAdapter->sub($a, $b, $scale));
73  }
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

EvalMath ilMathBaseAdapterTest::$evalMath
protected

Definition at line 31 of file ilMathBaseAdapterTest.php.

◆ $mathAdapter

ilMathAdapter ilMathBaseAdapterTest::$mathAdapter
protected

Definition at line 30 of file ilMathBaseAdapterTest.php.

◆ DEFAULT_SCALE

const ilMathBaseAdapterTest::DEFAULT_SCALE = 50
protected

Definition at line 28 of file ilMathBaseAdapterTest.php.


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