2018-02-24 05:12:09 +08:00
|
|
|
<?php
|
|
|
|
|
2020-05-23 23:43:29 +08:00
|
|
|
namespace Tests;
|
|
|
|
|
2018-02-24 05:12:09 +08:00
|
|
|
use App\Support\Math;
|
2019-07-16 03:14:40 +08:00
|
|
|
use App\Support\Units\Distance;
|
2018-02-24 05:12:09 +08:00
|
|
|
|
|
|
|
class MathTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test adding/subtracting a percentage
|
|
|
|
*/
|
|
|
|
public function testAddPercent()
|
|
|
|
{
|
|
|
|
$tests = [
|
2020-11-27 05:44:57 +08:00
|
|
|
['expected' => 112, 'fn' => Math::getPercent(100, 112)],
|
|
|
|
['expected' => 112, 'fn' => Math::getPercent(100, '112')],
|
|
|
|
['expected' => 112, 'fn' => Math::getPercent(100, '112%')],
|
|
|
|
['expected' => 112, 'fn' => Math::getPercent(100, '112%')],
|
|
|
|
['expected' => 112, 'fn' => Math::getPercent('100 ', '112')],
|
|
|
|
['expected' => 112.5, 'fn' => Math::getPercent('100', '112.5')],
|
|
|
|
['expected' => 88, 'fn' => Math::getPercent('100', 88)],
|
|
|
|
['expected' => 88, 'fn' => Math::getPercent('100', '88')],
|
|
|
|
['expected' => 88, 'fn' => Math::getPercent('100', '88 %')],
|
|
|
|
['expected' => 88, 'fn' => Math::getPercent('100', '88%')],
|
2018-02-24 05:12:09 +08:00
|
|
|
];
|
|
|
|
|
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']);
|
|
|
|
}
|
|
|
|
}
|
2019-07-16 03:14:40 +08:00
|
|
|
|
|
|
|
public function testDistanceMeasurement()
|
|
|
|
{
|
|
|
|
$dist = new Distance(1, 'mi');
|
|
|
|
$this->assertEquals(1609.34, $dist['m']);
|
|
|
|
$this->assertEquals(1.61, $dist['km']);
|
|
|
|
}
|
2018-02-24 05:12:09 +08:00
|
|
|
}
|