mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-16 10:15:13 +00:00
a348111e97
* tests: update to PHPUnit 6.0 with rector * fix namespaces on tests * composer + tests: use standard test namespace naming * update travis * resolve conflict * phpstan lvl 2 * phpstan lvl 3 * phpstan lvl 4 * phpstan lvl 5 * phpstan lvl 6 * phpstan lvl 7 * level max * resolve conflict * [cs] clean empty docs * composer: bump to PHPUnit 6.4 * cleanup * composer + travis: add phpstan * phpstan lvl 1 * composer: update dev deps * phpstan fixes * update Contributing with new tools * docs: link fixes, PHP version update * composer: drop php-cs-fixer, cs already handled by ecs * ecs: add old set rules * [cs] apply rest of rules
64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Phpml\Tests\Math\Distance;
|
|
|
|
use Phpml\Exception\InvalidArgumentException;
|
|
use Phpml\Math\Distance\Chebyshev;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ChebyshevTest extends TestCase
|
|
{
|
|
/**
|
|
* @var Chebyshev
|
|
*/
|
|
private $distanceMetric;
|
|
|
|
public function setUp(): void
|
|
{
|
|
$this->distanceMetric = new Chebyshev();
|
|
}
|
|
|
|
public function testThrowExceptionOnInvalidArguments(): void
|
|
{
|
|
$this->expectException(InvalidArgumentException::class);
|
|
$a = [0, 1, 2];
|
|
$b = [0, 2];
|
|
$this->distanceMetric->distance($a, $b);
|
|
}
|
|
|
|
public function testCalculateDistanceForOneDimension(): void
|
|
{
|
|
$a = [4];
|
|
$b = [2];
|
|
|
|
$expectedDistance = 2;
|
|
$actualDistance = $this->distanceMetric->distance($a, $b);
|
|
|
|
$this->assertEquals($expectedDistance, $actualDistance);
|
|
}
|
|
|
|
public function testCalculateDistanceForTwoDimensions(): void
|
|
{
|
|
$a = [4, 6];
|
|
$b = [2, 5];
|
|
|
|
$expectedDistance = 2;
|
|
$actualDistance = $this->distanceMetric->distance($a, $b);
|
|
|
|
$this->assertEquals($expectedDistance, $actualDistance);
|
|
}
|
|
|
|
public function testCalculateDistanceForThreeDimensions(): void
|
|
{
|
|
$a = [6, 10, 3];
|
|
$b = [2, 5, 5];
|
|
|
|
$expectedDistance = 5;
|
|
$actualDistance = $this->distanceMetric->distance($a, $b);
|
|
|
|
$this->assertEquals($expectedDistance, $actualDistance);
|
|
}
|
|
}
|