2018-02-24 05:12:09 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use App\Support\Math;
|
|
|
|
|
|
|
|
class MathTest extends TestCase
|
|
|
|
{
|
2018-08-27 00:40:04 +08:00
|
|
|
public function setUp()
|
|
|
|
{
|
2018-02-24 05:12:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test adding/subtracting a percentage
|
|
|
|
*/
|
|
|
|
public function testAddPercent()
|
|
|
|
{
|
|
|
|
$tests = [
|
|
|
|
['expected' => 112, 'fn' => Math::addPercent(100, 12)],
|
|
|
|
['expected' => 112, 'fn' => Math::addPercent(100, '12')],
|
|
|
|
['expected' => 112, 'fn' => Math::addPercent(100, '12%')],
|
|
|
|
['expected' => 112, 'fn' => Math::addPercent(100, '12 %')],
|
|
|
|
['expected' => 112, 'fn' => Math::addPercent('100 ', '12')],
|
|
|
|
['expected' => 112.5, 'fn' => Math::addPercent('100', '12.5')],
|
|
|
|
['expected' => 88, 'fn' => Math::addPercent('100', -12)],
|
|
|
|
['expected' => 88, 'fn' => Math::addPercent('100', '-12')],
|
|
|
|
['expected' => 88, 'fn' => Math::addPercent('100', '-12 %')],
|
|
|
|
['expected' => 88, 'fn' => Math::addPercent('100', '-12%')],
|
|
|
|
];
|
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
foreach ($tests as $test) {
|
2018-02-24 05:12:09 +08:00
|
|
|
$this->assertEquals($test['expected'], $test['fn']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|