-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from tadeubarbosa/master
feat: create helper functions
- Loading branch information
Showing
3 changed files
with
129 additions
and
1 deletion.
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,69 @@ | ||
<?php | ||
|
||
use Mattiasgeniar\Percentage\Percentage; | ||
|
||
if (!function_exists("percentage_between")) | ||
{ | ||
/** | ||
* @param float $a | ||
* @param float $b | ||
* @return float | ||
*/ | ||
function percentage_between(float $a, float $b): float | ||
{ | ||
return Percentage::differenceBetween($a, $b); | ||
} | ||
} | ||
|
||
if (!function_exists("percentage_abs_between")) | ||
{ | ||
/** | ||
* @param float $a | ||
* @param float $b | ||
* @return float | ||
*/ | ||
function percentage_abs_between(float $a, float $b): float | ||
{ | ||
return Percentage::absoluteDifferenceBetween($a, $b); | ||
} | ||
} | ||
|
||
if (!function_exists("percentage")) | ||
{ | ||
/** | ||
* @param float $a | ||
* @param float $b | ||
* @return float | ||
*/ | ||
function percentage(float $a, float $b): float | ||
{ | ||
return Percentage::calculate($a, $b); | ||
} | ||
} | ||
|
||
if (!function_exists("percentage_of")) | ||
{ | ||
/** | ||
* @param float $percentage | ||
* @param float $number | ||
* @return float | ||
*/ | ||
function percentage_of(float $percentage, float $number): float | ||
{ | ||
return Percentage::of($percentage, $number); | ||
} | ||
} | ||
|
||
if (!function_exists("percentage_extension")) | ||
{ | ||
/** | ||
* @param float $percentage | ||
* @param float $a | ||
* @param float $b | ||
* @return float | ||
*/ | ||
function percentage_extension(float $percentage, float $a, float $b): float | ||
{ | ||
return Percentage::extension($percentage, $a, $b); | ||
} | ||
} |
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,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mattiasgeniar\Percentage\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
final class HelpersTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_can_calculate_percentage_between(): void | ||
{ | ||
$result = percentage_between(1, 0); | ||
self::assertNotNull($result); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_can_calculate_percentage_abs_between(): void | ||
{ | ||
$result = percentage_abs_between(1, 0); | ||
self::assertNotNull($result); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_can_calculate_percentage(): void | ||
{ | ||
$result = percentage(1, 1); | ||
self::assertNotNull($result); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_can_calculate_percentage_of(): void | ||
{ | ||
$result = percentage_of(1, 1); | ||
self::assertNotNull($result); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_can_calculate_percentage_extension(): void | ||
{ | ||
$result = percentage_extension(1, 1, 1); | ||
self::assertNotNull($result); | ||
} | ||
|
||
} |