mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-28 15:56:36 +00:00
Ensure DataTransformer::testSet samples array is not empty (#204)
This commit is contained in:
parent
4562f1dfc9
commit
9e375ca544
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Phpml\SupportVectorMachine;
|
||||
|
||||
use Phpml\Exception\InvalidArgumentException;
|
||||
|
||||
class DataTransformer
|
||||
{
|
||||
public static function trainingSet(array $samples, array $labels, bool $targets = false): string
|
||||
@ -24,6 +26,10 @@ class DataTransformer
|
||||
|
||||
public static function testSet(array $samples): string
|
||||
{
|
||||
if (empty($samples)) {
|
||||
throw InvalidArgumentException::arrayCantBeEmpty();
|
||||
}
|
||||
|
||||
if (!is_array($samples[0])) {
|
||||
$samples = [$samples];
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Phpml\Tests\SupportVectorMachine;
|
||||
|
||||
use Phpml\Exception\InvalidArgumentException;
|
||||
use Phpml\SupportVectorMachine\DataTransformer;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@ -78,4 +79,12 @@ class DataTransformerTest extends TestCase
|
||||
|
||||
$this->assertEquals($probabilities, DataTransformer::probabilities($rawPredictions, $labels));
|
||||
}
|
||||
|
||||
public function testThrowExceptionWhenTestSetIsEmpty(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('The array has zero elements');
|
||||
|
||||
DataTransformer::testSet([]);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user