Skip to content

Commit

Permalink
Merge pull request #7 from tadeubarbosa/master
Browse files Browse the repository at this point in the history
feat: create helper functions
  • Loading branch information
mattiasgeniar authored Feb 1, 2021
2 parents 671ce91 + bdfe70d commit 1a2c9a3
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 1 deletion.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
"autoload": {
"psr-4": {
"Mattiasgeniar\\Percentage\\": "src"
}
},
"files": [
"src/Helpers.php"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
69 changes: 69 additions & 0 deletions src/Helpers.php
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);
}
}
56 changes: 56 additions & 0 deletions tests/HelpersTest.php
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);
}

}

0 comments on commit 1a2c9a3

Please sign in to comment.