2016-04-07 20:36:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare (strict_types = 1);
|
|
|
|
|
|
|
|
namespace tests\Phpml\Dataset;
|
|
|
|
|
|
|
|
use Phpml\Dataset\CsvDataset;
|
|
|
|
|
|
|
|
class CsvDatasetTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @expectedException \Phpml\Exception\DatasetException
|
|
|
|
*/
|
|
|
|
public function testThrowExceptionOnMissingFile()
|
|
|
|
{
|
|
|
|
new CsvDataset('missingFile', 3);
|
|
|
|
}
|
|
|
|
|
2016-04-16 19:24:40 +00:00
|
|
|
public function testSampleCsvDatasetWithHeaderRow()
|
2016-04-07 20:36:02 +00:00
|
|
|
{
|
|
|
|
$filePath = dirname(__FILE__).'/Resources/dataset.csv';
|
|
|
|
|
|
|
|
$dataset = new CsvDataset($filePath, 2, true);
|
|
|
|
|
|
|
|
$this->assertEquals(10, count($dataset->getSamples()));
|
|
|
|
$this->assertEquals(10, count($dataset->getLabels()));
|
|
|
|
}
|
2016-04-16 19:24:40 +00:00
|
|
|
|
|
|
|
public function testSampleCsvDatasetWithoutHeaderRow()
|
|
|
|
{
|
|
|
|
$filePath = dirname(__FILE__).'/Resources/dataset.csv';
|
|
|
|
|
|
|
|
$dataset = new CsvDataset($filePath, 2, false);
|
|
|
|
|
|
|
|
$this->assertEquals(11, count($dataset->getSamples()));
|
|
|
|
$this->assertEquals(11, count($dataset->getLabels()));
|
|
|
|
}
|
2016-04-07 20:36:02 +00:00
|
|
|
}
|