mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-10 17:28:40 +00:00
fix tests
This commit is contained in:
parent
af9a7e1f29
commit
326e2172ec
|
|
@ -52,7 +52,7 @@ final class MetricsND
|
||||||
*/
|
*/
|
||||||
public static function manhattan(array $a, array $b) : float
|
public static function manhattan(array $a, array $b) : float
|
||||||
{
|
{
|
||||||
if (\count($a) !== \count($b)) {
|
if (\count($a) > \count($b)) {
|
||||||
throw new InvalidDimensionException(\count($a) . 'x' . \count($b));
|
throw new InvalidDimensionException(\count($a) . 'x' . \count($b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,6 +78,10 @@ final class MetricsND
|
||||||
*/
|
*/
|
||||||
public static function euclidean(array $a, array $b) : float
|
public static function euclidean(array $a, array $b) : float
|
||||||
{
|
{
|
||||||
|
if (\count($a) > \count($b)) {
|
||||||
|
throw new InvalidDimensionException(\count($a) . 'x' . \count($b));
|
||||||
|
}
|
||||||
|
|
||||||
$dist = 0.0;
|
$dist = 0.0;
|
||||||
foreach ($a as $key => $e) {
|
foreach ($a as $key => $e) {
|
||||||
$dist += \abs($e - $b[$key]) ** 2;
|
$dist += \abs($e - $b[$key]) ** 2;
|
||||||
|
|
@ -94,10 +98,16 @@ final class MetricsND
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float
|
||||||
*
|
*
|
||||||
|
* @throws InvalidDimensionException
|
||||||
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static function cosine(array $a, array $b) : float
|
public static function cosine(array $a, array $b) : float
|
||||||
{
|
{
|
||||||
|
if (\count($a) > \count($b)) {
|
||||||
|
throw new InvalidDimensionException(\count($a) . 'x' . \count($b));
|
||||||
|
}
|
||||||
|
|
||||||
$dotProduct = 0;
|
$dotProduct = 0;
|
||||||
foreach ($a as $id => $_) {
|
foreach ($a as $id => $_) {
|
||||||
$dotProduct += $a[$id] * $b[$id];
|
$dotProduct += $a[$id] * $b[$id];
|
||||||
|
|
@ -138,7 +148,7 @@ final class MetricsND
|
||||||
*/
|
*/
|
||||||
public static function chebyshev(array $a, array $b) : float
|
public static function chebyshev(array $a, array $b) : float
|
||||||
{
|
{
|
||||||
if (\count($a) !== \count($b)) {
|
if (\count($a) > \count($b)) {
|
||||||
throw new InvalidDimensionException(\count($a) . 'x' . \count($b));
|
throw new InvalidDimensionException(\count($a) . 'x' . \count($b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -167,7 +177,7 @@ final class MetricsND
|
||||||
*/
|
*/
|
||||||
public static function minkowski(array $a, array $b, int $lambda) : float
|
public static function minkowski(array $a, array $b, int $lambda) : float
|
||||||
{
|
{
|
||||||
if (\count($a) !== \count($b)) {
|
if (\count($a) > \count($b)) {
|
||||||
throw new InvalidDimensionException(\count($a) . 'x' . \count($b));
|
throw new InvalidDimensionException(\count($a) . 'x' . \count($b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,7 +205,7 @@ final class MetricsND
|
||||||
*/
|
*/
|
||||||
public static function canberra(array $a, array $b) : float
|
public static function canberra(array $a, array $b) : float
|
||||||
{
|
{
|
||||||
if (\count($a) !== \count($b)) {
|
if (\count($a) > \count($b)) {
|
||||||
throw new InvalidDimensionException(\count($a) . 'x' . \count($b));
|
throw new InvalidDimensionException(\count($a) . 'x' . \count($b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -223,7 +233,7 @@ final class MetricsND
|
||||||
*/
|
*/
|
||||||
public static function brayCurtis(array $a, array $b) : float
|
public static function brayCurtis(array $a, array $b) : float
|
||||||
{
|
{
|
||||||
if (\count($a) !== \count($b)) {
|
if (\count($a) > \count($b)) {
|
||||||
throw new InvalidDimensionException(\count($a) . 'x' . \count($b));
|
throw new InvalidDimensionException(\count($a) . 'x' . \count($b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,7 +263,7 @@ final class MetricsND
|
||||||
*/
|
*/
|
||||||
public static function angularSeparation(array $a, array $b) : float
|
public static function angularSeparation(array $a, array $b) : float
|
||||||
{
|
{
|
||||||
if (\count($a) !== \count($b)) {
|
if (\count($a) > \count($b)) {
|
||||||
throw new InvalidDimensionException(\count($a) . 'x' . \count($b));
|
throw new InvalidDimensionException(\count($a) . 'x' . \count($b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ final class MetricsNDTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||||
|
|
||||||
MetricsND::manhattan([3, 6, 4], [4, 6, 8, 3]);
|
MetricsND::manhattan([4, 6, 8, 3], [3, 6, 4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
||||||
|
|
@ -135,7 +135,7 @@ final class MetricsNDTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||||
|
|
||||||
MetricsND::euclidean([3, 6, 4], [4, 6, 8, 3]);
|
MetricsND::euclidean([4, 6, 8, 3], [3, 6, 4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
||||||
|
|
@ -144,7 +144,7 @@ final class MetricsNDTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||||
|
|
||||||
MetricsND::chebyshev([3, 6, 4], [4, 6, 8, 3]);
|
MetricsND::chebyshev([4, 6, 8, 3], [3, 6, 4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
||||||
|
|
@ -153,7 +153,7 @@ final class MetricsNDTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||||
|
|
||||||
MetricsND::minkowski([3, 6, 4], [4, 6, 8, 3], 2);
|
MetricsND::minkowski([4, 6, 8, 3], [3, 6, 4], 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
||||||
|
|
@ -162,7 +162,7 @@ final class MetricsNDTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||||
|
|
||||||
MetricsND::canberra([3, 6, 4], [4, 6, 8, 3]);
|
MetricsND::canberra([4, 6, 8, 3], [3, 6, 4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
||||||
|
|
@ -171,7 +171,7 @@ final class MetricsNDTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||||
|
|
||||||
MetricsND::cosine([3, 6, 4], [4, 6, 8, 3]);
|
MetricsND::cosine([4, 6, 8, 3], [3, 6, 4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
||||||
|
|
@ -180,7 +180,7 @@ final class MetricsNDTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||||
|
|
||||||
MetricsND::brayCurtis([3, 6, 4], [4, 6, 8, 3]);
|
MetricsND::brayCurtis([4, 6, 8, 3], [3, 6, 4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
||||||
|
|
@ -189,7 +189,7 @@ final class MetricsNDTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||||
|
|
||||||
MetricsND::angularSeparation([3, 6, 4], [4, 6, 8, 3]);
|
MetricsND::angularSeparation([4, 6, 8, 3], [3, 6, 4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
#[\PHPUnit\Framework\Attributes\Group('framework')]
|
||||||
|
|
@ -198,6 +198,6 @@ final class MetricsNDTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
$this->expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||||
|
|
||||||
MetricsND::hamming([3, 6, 4], [4, 6, 8, 3]);
|
MetricsND::hamming([4, 6, 8, 3], [3, 6, 4]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user