ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilMathTest.php
Go to the documentation of this file.
1<?php
2
19use PHPUnit\Framework\TestCase;
20
24class ilMathTest extends TestCase
25{
27
31 protected function setUp(): void
32 {
34 $this->eval_math = new EvalMath();
35 }
36
37 #[\PHPUnit\Framework\Attributes\DataProvider('gcdData')]
38 public function testGcd(string $a, string $b, string $result): void
39 {
40 $this->assertEquals($result, ilMath::getGreatestCommonDivisor($a, $b));
41 }
42
46 public static function gcdData(): array
47 {
48 return [
49 ['1254', '5298', '6'],
50 ['41414124', '41414124', '41414124']
51 ];
52 }
53
55 {
56 $this->assertEqualsWithDelta(100.0, (float) $this->eval_math->evaluate('1E+2'), 0.000001);
57 $this->assertEqualsWithDelta(5400000.0, (float) $this->eval_math->evaluate('5.4E+6'), 0.001);
58 $this->assertEqualsWithDelta(5400000.0, (float) $this->eval_math->evaluate('54E5'), 0.001);
59 $this->assertEqualsWithDelta(0.0054, (float) $this->eval_math->evaluate('5.4E-3'), 0.0000001);
60
61 $lower = (float) $this->eval_math->evaluate('5.4E+24');
62 $upper = (float) $this->eval_math->evaluate('5.6E+24');
63 $this->assertGreaterThan(38000.0, $lower);
64 $this->assertGreaterThan($lower, $upper);
65
66 if (extension_loaded('bcmath')) {
67 $lower_text = (string) $this->eval_math->evaluate('5.4E+24');
68 $upper_text = (string) $this->eval_math->evaluate('5.6E+24');
69 $this->assertSame(0, bccomp($lower_text, '5400000000000000000000000', 0), $lower_text);
70 $this->assertSame(0, bccomp($upper_text, '5600000000000000000000000', 0), $upper_text);
71 }
72 }
73}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static gcdData()
Definition: ilMathTest.php:46
EvalMath $eval_math
Definition: ilMathTest.php:26
testGcd(string $a, string $b, string $result)
Definition: ilMathTest.php:38
testPlusScientificNotationIsPowerOfTen()
Definition: ilMathTest.php:54
setUp()
@inheritDoc
Definition: ilMathTest.php:31
static getFirstValidAdapter()
static setDefaultAdapter(ilMathAdapter $adapter)
static getGreatestCommonDivisor($a, $b)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples