php-ml/tests/Phpml/Math/Distance/ManhattanTest.php

66 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2016-11-20 21:53:17 +00:00
declare(strict_types=1);
namespace tests\Phpml\Metric;
2016-04-20 21:56:33 +00:00
use Phpml\Math\Distance\Manhattan;
2017-02-03 11:58:25 +00:00
use PHPUnit\Framework\TestCase;
2017-02-03 11:58:25 +00:00
class ManhattanTest extends TestCase
{
/**
* @var Manhattan
*/
private $distanceMetric;
public function setUp()
{
$this->distanceMetric = new Manhattan();
}
/**
* @expectedException \Phpml\Exception\InvalidArgumentException
*/
public function testThrowExceptionOnInvalidArguments()
{
$a = [0, 1, 2];
$b = [0, 2];
$this->distanceMetric->distance($a, $b);
}
public function testCalculateDistanceForOneDimension()
{
$a = [4];
$b = [2];
$expectedDistance = 2;
$actualDistance = $this->distanceMetric->distance($a, $b);
$this->assertEquals($expectedDistance, $actualDistance);
}
public function testCalculateDistanceForTwoDimensions()
{
$a = [4, 6];
$b = [2, 5];
$expectedDistance = 3;
$actualDistance = $this->distanceMetric->distance($a, $b);
$this->assertEquals($expectedDistance, $actualDistance);
}
public function testCalculateDistanceForThreeDimensions()
{
$a = [6, 10, 3];
$b = [2, 5, 5];
$expectedDistance = 11;
$actualDistance = $this->distanceMetric->distance($a, $b);
$this->assertEquals($expectedDistance, $actualDistance);
}
}