Fix: phpunit include tests path (#230)
* Fix phpunit include path * Add tests for Covariance
This commit is contained in:
parent
53f8a89556
commit
52c9ba8291
|
@ -9,7 +9,7 @@
|
|||
enforceTimeLimit="true"
|
||||
>
|
||||
<testsuite name="PHP-ML Test Suite">
|
||||
<directory>tests/*</directory>
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
|
||||
<filter>
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace Phpml\Math\Statistic;
|
||||
|
||||
use Exception;
|
||||
use Phpml\Exception\InvalidArgumentException;
|
||||
|
||||
class Covariance
|
||||
|
@ -64,7 +63,7 @@ class Covariance
|
|||
}
|
||||
|
||||
if ($i < 0 || $k < 0 || $i >= $n || $k >= $n) {
|
||||
throw new Exception('Given indices i and k do not match with the dimensionality of data');
|
||||
throw new InvalidArgumentException('Given indices i and k do not match with the dimensionality of data');
|
||||
}
|
||||
|
||||
if ($meanX === null || $meanY === null) {
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Phpml\Tests\Math\Statistic;
|
||||
|
||||
use Phpml\Exception\InvalidArgumentException;
|
||||
use Phpml\Math\Statistic\Covariance;
|
||||
use Phpml\Math\Statistic\Mean;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
@ -59,4 +60,46 @@ class CovarianceTest extends TestCase
|
|||
$covariance = Covariance::covarianceMatrix($matrix, [$meanX, $meanY]);
|
||||
$this->assertEquals($knownCovariance, $covariance, '', $epsilon);
|
||||
}
|
||||
|
||||
public function testThrowExceptionOnEmptyX(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
Covariance::fromXYArrays([], [1, 2, 3]);
|
||||
}
|
||||
|
||||
public function testThrowExceptionOnEmptyY(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
Covariance::fromXYArrays([1, 2, 3], []);
|
||||
}
|
||||
|
||||
public function testThrowExceptionOnToSmallArrayIfSample(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
Covariance::fromXYArrays([1], [2], true);
|
||||
}
|
||||
|
||||
public function testThrowExceptionIfEmptyDataset(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
Covariance::fromDataset([], 0, 1);
|
||||
}
|
||||
|
||||
public function testThrowExceptionOnToSmallDatasetIfSample(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
Covariance::fromDataset([1], 0, 1);
|
||||
}
|
||||
|
||||
public function testThrowExceptionWhenKIndexIsOutOfBound(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
Covariance::fromDataset([1, 2, 3], 2, 5);
|
||||
}
|
||||
|
||||
public function testThrowExceptionWhenIIndexIsOutOfBound(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
Covariance::fromDataset([1, 2, 3], 5, 2);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue