Skip to content

Commit

Permalink
Added Math.* Constans
Browse files Browse the repository at this point in the history
  • Loading branch information
fadrian06 committed Jan 8, 2024
1 parent d3dc362 commit 399db67
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Tasks.todo
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,20 @@ JSPHP:
☐ Run the reviver param with keys recursively iteration
✔ Create test for other data types (currently only test for strings) @done (4/12/2023, 20:50:09)
☐ JSON.stringify()
String.method signature overload for the replacer param @done (23-12-30 14:26)
Method signature overload for the replacer param @done (23-12-30 14:26)
--- ✄ -----------------------
Math:
✔ Core behaviour @done (05/01/2024 14:41:14)
✔ Make class no instantiable @done (05/01/2024 14:41:09)
☐ Static properties
Math.E
Math.LN10
Math.LN2
Math.LOG10E
Math.LOG2E
Math.PI
Math.SQRT1_2
Math.SQRT2
Math.E @done (07/01/2024 11:20:16)
Math.LN10 @done (07/01/2024 22:19:17)
Math.LN2 @done (07/01/2024 23:30:09)
Math.LOG10E @done (07/01/2024 23:30:09)
Math.LOG2E @done (07/01/2024 23:30:10)
Math.PI @done (07/01/2024 23:30:10)
Math.SQRT1_2 @done (07/01/2024 23:30:12)
Math.SQRT2 @done (07/01/2024 23:30:13)
☐ Static methods
☐ Math.abs()
☐ Math.acos()
Expand Down
28 changes: 28 additions & 0 deletions tests/PHP/Math/ETest.php
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());
}
}
22 changes: 22 additions & 0 deletions tests/PHP/Math/LN10Test.php
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();
}
}
23 changes: 23 additions & 0 deletions tests/PHP/Math/LN2Test.php
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;
}
}
23 changes: 23 additions & 0 deletions tests/PHP/Math/LOG10ETest.php
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;
}
}
23 changes: 23 additions & 0 deletions tests/PHP/Math/LOG2ETest.php
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;
}
}
30 changes: 30 additions & 0 deletions tests/PHP/Math/PITest.php
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));
}
}
23 changes: 23 additions & 0 deletions tests/PHP/Math/SQRT1_2Test.php
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;
}
}
23 changes: 23 additions & 0 deletions tests/PHP/Math/SQRT2Test.php
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;
}
}

0 comments on commit 399db67

Please sign in to comment.