ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilMathBaseAdapterTestCase Class Reference
+ Inheritance diagram for ilMathBaseAdapterTestCase:
+ Collaboration diagram for ilMathBaseAdapterTestCase:

Public Member Functions

 testAdd (string $a, string $b, string $result, int $scale)
 
 testSub (string $a, string $b, string $result, int $scale)
 
 testMul (string $a, string $b, string $result, int $scale)
 
 testDiv (string $a, string $b, string $result, int $scale)
 
 testSqrt (string $a, string $result, ?int $scale)
 
 testPow (string $a, string $b, string $result, ?int $scale)
 
 testMod (string $a, string $b, string $result)
 
 testEquals (string $a, string $b, bool $result, ?int $scale)
 
 testCalculation (string $formula, string $result, int $scale)
 
 testDivisionsByZero ()
 
 testModuloByZero ()
 

Static Public Member Functions

static addData ()
 
static subData ()
 
static mulData ()
 
static divData ()
 
static modData ()
 
static sqrtData ()
 
static powData ()
 
static equalsData ()
 
static calcData ()
 

Protected Member Functions

 setUp ()
 @inheritDoc More...
 

Protected Attributes

const DEFAULT_SCALE = 50
 
ilMathAdapter $mathAdapter
 
EvalMath $evalMath
 

Private Member Functions

 assertEqualNumbers (string $expected, string $actual)
 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 24 of file ilMathBaseAdapterTestCase.php.

Member Function Documentation

◆ addData()

static ilMathBaseAdapterTestCase::addData ( )
static
Returns
array

Definition at line 138 of file ilMathBaseAdapterTestCase.php.

138 : array
139 {
140 return [
141 ['1', '2', '3', self::DEFAULT_SCALE]
142 ];
143 }

References DEFAULT_SCALE.

◆ assertEqualNumbers()

ilMathBaseAdapterTestCase::assertEqualNumbers ( string  $expected,
string  $actual 
)
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
\SebastianBergmann\Comparator\ScalarComparator
Parameters
string$expected
string$actual

@noinspection PhpUnitTestsInspection

Definition at line 49 of file ilMathBaseAdapterTestCase.php.

49 : void
50 {
52 $this->assertTrue(
53 $actual == $expected,
54 sprintf("Failed asserting that '%s' is numerically equal to '%s'.", $actual, $expected)
55 );
56 }

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

+ Here is the caller graph for this function:

◆ calcData()

static ilMathBaseAdapterTestCase::calcData ( )
static

Definition at line 226 of file ilMathBaseAdapterTestCase.php.

226 : array
227 {
228 return [
229 ['3+5', '8', self::DEFAULT_SCALE],
230 ['-3+5', '2', self::DEFAULT_SCALE],
231 ['3*6+5', '23', self::DEFAULT_SCALE],
232 ['10/2', '5', self::DEFAULT_SCALE],
233 ['13/60', '0.2166666666666', 13],
234 ['(-(-8)-sqrt((-8)^2-4*(7)))/(2)', '1', self::DEFAULT_SCALE],
235 ['(-(-8)+sqrt((-8)^2-4*(7)))/(2)', '7', self::DEFAULT_SCALE],
236 ['(-(-41)-sqrt((-41)^2-4*(1)*(5)))/(2*(1))', '0.122', 3],
237 ['(-(-41)+sqrt((-41)^2-4*(1)*(5)))/(2*(1))', '40.877', 3],
238 ['4^2-2*4+0.5*-16', '0', self::DEFAULT_SCALE],
239 ['-2^2-2*-2+0.5*-16', '-8', self::DEFAULT_SCALE]
240 ];
241 }

References DEFAULT_SCALE.

◆ divData()

static ilMathBaseAdapterTestCase::divData ( )
static
Returns
array

Definition at line 170 of file ilMathBaseAdapterTestCase.php.

170 : array
171 {
172 return [
173 'Division with integer operands' => ['1', '2', '0.5', self::DEFAULT_SCALE],
174 'Division with empty string operand' => ['', '2', '0', self::DEFAULT_SCALE],
175 'Division with decimal operands' => ['3.75', '2.5', '1.5', self::DEFAULT_SCALE],
176 ];
177 }

References DEFAULT_SCALE.

◆ equalsData()

static ilMathBaseAdapterTestCase::equalsData ( )
static
Returns
array

Definition at line 215 of file ilMathBaseAdapterTestCase.php.

215 : array
216 {
217 return [
218 ['3', '3', true, null],
219 ['27.424', '27.424', true, 5]
220 ];
221 }

◆ modData()

static ilMathBaseAdapterTestCase::modData ( )
static
Returns
array

Definition at line 182 of file ilMathBaseAdapterTestCase.php.

182 : array
183 {
184 return [
185 ['1', '2', '1']
186 ];
187 }

◆ mulData()

static ilMathBaseAdapterTestCase::mulData ( )
static
Returns
array

Definition at line 158 of file ilMathBaseAdapterTestCase.php.

158 : array
159 {
160 return [
161 'Multiplication with integer operands' => ['1', '2', '2', self::DEFAULT_SCALE],
162 'Multiplication with empty string operand' => ['1', '', '0', self::DEFAULT_SCALE],
163 'Multiplication with decimal operands' => ['1.5', '2.5', '3.75', self::DEFAULT_SCALE]
164 ];
165 }

References DEFAULT_SCALE.

◆ powData()

static ilMathBaseAdapterTestCase::powData ( )
static
Returns
array

Reimplemented in ilMathBCAdapterTest.

Definition at line 205 of file ilMathBaseAdapterTestCase.php.

205 : array
206 {
207 return [
208 ['3', '2', '9', self::DEFAULT_SCALE]
209 ];
210 }

References DEFAULT_SCALE.

◆ setUp()

ilMathBaseAdapterTestCase::setUp ( )
protected

@inheritDoc

Reimplemented in ilMathBCAdapterTest, and ilMathPhpAdapterTest.

Definition at line 34 of file ilMathBaseAdapterTestCase.php.

34 : void
35 {
36 ilMath::setDefaultAdapter($this->mathAdapter);
37 $this->evalMath = new EvalMath();
39 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static setDefaultAdapter(ilMathAdapter $adapter)

References ilMath\setDefaultAdapter(), and setUp().

+ Here is the call graph for this function:

◆ sqrtData()

static ilMathBaseAdapterTestCase::sqrtData ( )
static
Returns
array

Definition at line 192 of file ilMathBaseAdapterTestCase.php.

192 : array
193 {
194 return [
195 ['9', '3', self::DEFAULT_SCALE],
196 ['4294967296', '65536', self::DEFAULT_SCALE],
197 ['12345678901234567890', '3513641828', null],
198 ['12345678901234567890', '3513641828.82', 2]
199 ];
200 }

References DEFAULT_SCALE.

◆ subData()

static ilMathBaseAdapterTestCase::subData ( )
static
Returns
array

Definition at line 148 of file ilMathBaseAdapterTestCase.php.

148 : array
149 {
150 return [
151 ['1', '2', '-1', self::DEFAULT_SCALE]
152 ];
153 }

References DEFAULT_SCALE.

◆ testAdd()

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

Definition at line 59 of file ilMathBaseAdapterTestCase.php.

59 : void
60 {
61 $this->assertEqualNumbers($result, $this->mathAdapter->add($a, $b, $scale));
62 }
assertEqualNumbers(string $expected, string $actual)
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

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

+ Here is the call graph for this function:

◆ testCalculation()

ilMathBaseAdapterTestCase::testCalculation ( string  $formula,
string  $result,
int  $scale 
)

Definition at line 110 of file ilMathBaseAdapterTestCase.php.

110 : void
111 {
112 $this->assertEqualNumbers($result, ilMath::_applyScale($this->evalMath->evaluate($formula), $scale));
113 }

References assertEqualNumbers().

+ Here is the call graph for this function:

◆ testDiv()

ilMathBaseAdapterTestCase::testDiv ( string  $a,
string  $b,
string  $result,
int  $scale 
)

Definition at line 77 of file ilMathBaseAdapterTestCase.php.

77 : void
78 {
79 $this->assertEqualNumbers($result, $this->mathAdapter->div($a, $b, $scale));
80 }

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

+ Here is the call graph for this function:

◆ testDivisionsByZero()

ilMathBaseAdapterTestCase::testDivisionsByZero ( )

Definition at line 118 of file ilMathBaseAdapterTestCase.php.

118 : void
119 {
120 $this->expectException(ilMathDivisionByZeroException::class);
121
122 $this->mathAdapter->div(1, 0);
123 }

◆ testEquals()

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

Definition at line 104 of file ilMathBaseAdapterTestCase.php.

104 : void
105 {
106 $this->assertEqualNumbers($result, $this->mathAdapter->equals($a, $b, $scale));
107 }

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

+ Here is the call graph for this function:

◆ testMod()

ilMathBaseAdapterTestCase::testMod ( string  $a,
string  $b,
string  $result 
)
Exceptions
ilMathDivisionByZeroException

Definition at line 98 of file ilMathBaseAdapterTestCase.php.

98 : void
99 {
100 $this->assertEqualNumbers($result, $this->mathAdapter->mod($a, $b));
101 }

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

+ Here is the call graph for this function:

◆ testModuloByZero()

ilMathBaseAdapterTestCase::testModuloByZero ( )

Definition at line 128 of file ilMathBaseAdapterTestCase.php.

128 : void
129 {
130 $this->expectException(ilMathDivisionByZeroException::class);
131
132 $this->mathAdapter->mod(1, 0);
133 }

◆ testMul()

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

Definition at line 71 of file ilMathBaseAdapterTestCase.php.

71 : void
72 {
73 $this->assertEqualNumbers($result, $this->mathAdapter->mul($a, $b, $scale));
74 }

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

+ Here is the call graph for this function:

◆ testPow()

ilMathBaseAdapterTestCase::testPow ( string  $a,
string  $b,
string  $result,
?int  $scale 
)

Definition at line 89 of file ilMathBaseAdapterTestCase.php.

89 : void
90 {
91 $this->assertEqualNumbers($result, $this->mathAdapter->pow($a, $b, $scale));
92 }

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

+ Here is the call graph for this function:

◆ testSqrt()

ilMathBaseAdapterTestCase::testSqrt ( string  $a,
string  $result,
?int  $scale 
)

Definition at line 83 of file ilMathBaseAdapterTestCase.php.

83 : void
84 {
85 $this->assertEqualNumbers($result, $this->mathAdapter->sqrt($a, $scale));
86 }

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

+ Here is the call graph for this function:

◆ testSub()

ilMathBaseAdapterTestCase::testSub ( string  $a,
string  $b,
string  $result,
int  $scale 
)

Definition at line 65 of file ilMathBaseAdapterTestCase.php.

65 : void
66 {
67 $this->assertEqualNumbers($result, $this->mathAdapter->sub($a, $b, $scale));
68 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $evalMath

EvalMath ilMathBaseAdapterTestCase::$evalMath
protected

Definition at line 29 of file ilMathBaseAdapterTestCase.php.

◆ $mathAdapter

ilMathAdapter ilMathBaseAdapterTestCase::$mathAdapter
protected

Definition at line 28 of file ilMathBaseAdapterTestCase.php.

◆ DEFAULT_SCALE

const ilMathBaseAdapterTestCase::DEFAULT_SCALE = 50
protected

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