php-ml/tests/Dataset/CsvDatasetTest.php

49 lines
1.3 KiB
PHP
Raw Normal View History

2016-04-07 20:36:02 +00:00
<?php
2016-11-20 21:53:17 +00:00
declare(strict_types=1);
2016-04-07 20:36:02 +00:00
namespace Phpml\Tests\Dataset;
2016-04-07 20:36:02 +00:00
use Phpml\Dataset\CsvDataset;
use Phpml\Exception\FileException;
2017-02-03 11:58:25 +00:00
use PHPUnit\Framework\TestCase;
2016-04-07 20:36:02 +00:00
2017-02-03 11:58:25 +00:00
class CsvDatasetTest extends TestCase
2016-04-07 20:36:02 +00:00
{
public function testThrowExceptionOnMissingFile(): void
2016-04-07 20:36:02 +00:00
{
$this->expectException(FileException::class);
2016-04-07 20:36:02 +00:00
new CsvDataset('missingFile', 3);
}
public function testSampleCsvDatasetWithHeaderRow(): void
2016-04-07 20:36:02 +00:00
{
$filePath = dirname(__FILE__).'/Resources/dataset.csv';
$dataset = new CsvDataset($filePath, 2, true);
2018-10-28 06:44:52 +00:00
self::assertCount(10, $dataset->getSamples());
self::assertCount(10, $dataset->getTargets());
2016-04-07 20:36:02 +00:00
}
2016-04-16 19:24:40 +00:00
public function testSampleCsvDatasetWithoutHeaderRow(): void
2016-04-16 19:24:40 +00:00
{
$filePath = dirname(__FILE__).'/Resources/dataset.csv';
$dataset = new CsvDataset($filePath, 2, false);
2018-10-28 06:44:52 +00:00
self::assertCount(11, $dataset->getSamples());
self::assertCount(11, $dataset->getTargets());
2016-04-16 19:24:40 +00:00
}
2017-08-21 06:08:54 +00:00
public function testLongCsvDataset(): void
2017-08-21 06:08:54 +00:00
{
$filePath = dirname(__FILE__).'/Resources/longdataset.csv';
$dataset = new CsvDataset($filePath, 1000, false);
2018-10-28 06:44:52 +00:00
self::assertCount(1000, $dataset->getSamples()[0]);
self::assertEquals('label', $dataset->getTargets()[0]);
2017-08-21 06:08:54 +00:00
}
2016-04-07 20:36:02 +00:00
}