-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
204 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\PHP\Math; | ||
|
||
use Math; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class ETest extends TestCase { | ||
function test_Demo_Math_E(): void { | ||
$compoundOneYear = function (float $interestRate, int $currentVal): float { | ||
return $currentVal * Math::E ** $interestRate; | ||
}; | ||
|
||
self::assertSame(2.718281828459045, Math::E); | ||
self::assertSame(2.7182804690957534, (1 + 1 / 1000000) ** 1000000); | ||
self::assertSame(105.12710963760242, $compoundOneYear(0.05, 100)); | ||
} | ||
|
||
function test_Using_Math_E(): void { | ||
$getNapier = function (): float { | ||
return Math::E; | ||
}; | ||
|
||
self::assertSame(2.718281828459045, $getNapier()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\PHP\Math; | ||
|
||
use Math; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class LN10Test extends TestCase { | ||
function test_Demo_Math_LN10(): void { | ||
$getNatLog10 = function (): float { | ||
return Math::LN10; | ||
}; | ||
|
||
self::assertSame(2.302585092994046, $getNatLog10()); | ||
|
||
// TODO: Float to string coercion lose precision | ||
// self::expectOutputString('2.302585092994046'); | ||
// echo $getNatLog10(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\PHP\Math; | ||
|
||
use Math; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class LN2Test extends TestCase { | ||
/*function test_Demo_Math_LN2(): void { | ||
self::expectOutputString('0.6931471805599453'); | ||
echo self::getNatLog2(); | ||
}*/ | ||
|
||
function test_Using_Math_LN2(): void { | ||
self::assertSame(0.6931471805599453, self::getNatLog2()); | ||
} | ||
|
||
private static function getNatLog2(): float { | ||
return Math::LN2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\PHP\Math; | ||
|
||
use Math; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class LOG10ETest extends TestCase { | ||
// function test_Demo_Math_log10e(): void { | ||
// self::expectOutputString('0.4342944819032518'); | ||
// echo self::getLog10e(); | ||
// } | ||
|
||
function test_Using_Math_LOG10E(): void { | ||
self::assertSame(0.4342944819032518, self::getLog10e()); | ||
} | ||
|
||
private static function getLog10e(): float { | ||
return Math::LOG10E; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\PHP\Math; | ||
|
||
use Math; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class LOG2ETest extends TestCase { | ||
// function test_Demo_Math_log2e(): void { | ||
// self::expectOutputString('1.4426950408889634'); | ||
// echo self::getLog2e(); | ||
// } | ||
|
||
function test_Using_Math_LOG10E(): void { | ||
self::assertSame(1.4426950408889634, self::getLog2e()); | ||
} | ||
|
||
private static function getLog2e(): float { | ||
return Math::LOG2E; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\PHP\Math; | ||
|
||
use Math; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class PITest extends TestCase { | ||
function test_Demo_Math_PI(): void { | ||
$calculateCircumference = function (float $radius): float { | ||
return 2 * Math::PI * $radius; | ||
}; | ||
|
||
self::assertSame(3.141592653589793, Math::PI); | ||
self::assertSame(62.83185307179586, $calculateCircumference(10)); | ||
|
||
// self::expectOutputString('62.83185307179586'); | ||
// echo $calculateCircumference(10); | ||
} | ||
|
||
function test_Using_Math_PI(): void { | ||
$calculateCircumference = function (float $radius): float { | ||
return Math::PI * ($radius + $radius); | ||
}; | ||
|
||
self::assertSame(6.283185307179586, $calculateCircumference(1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\PHP\Math; | ||
|
||
use Math; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class SQRT1_2Test extends TestCase { | ||
/*function test_Demo_Math_SQRT1_2(): void { | ||
self::expectOutputString('0.7071067811865476'); | ||
echo self::getRoot1Over2(); | ||
}*/ | ||
|
||
function test_Using_Math_SQRT1_2(): void { | ||
self::assertSame(0.7071067811865476, self::getRoot1Over2()); // | ||
} | ||
|
||
private static function getRoot1Over2(): float { | ||
return Math::SQRT1_2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\PHP\Math; | ||
|
||
use Math; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class SQRT2Test extends TestCase { | ||
/*function test_Demo_Math_SQRT2(): void { | ||
self::expectOutputString('1.4142135623730951'); | ||
echo self::getRoot2(); | ||
}*/ | ||
|
||
function test_Using_Math_SQRT2(): void { | ||
self::assertSame(1.4142135623730951, self::getRoot2()); // | ||
} | ||
|
||
private static function getRoot2(): float { | ||
return Math::SQRT2; | ||
} | ||
} |