php-ml/tests/Phpml/Dataset/CsvDatasetTest.php

40 lines
959 B
PHP
Raw Normal View History

2016-04-07 22:36:02 +02:00
<?php
2016-11-20 22:53:17 +01:00
declare(strict_types=1);
2016-04-07 22:36:02 +02:00
namespace tests\Phpml\Dataset;
use Phpml\Dataset\CsvDataset;
2017-02-03 12:58:25 +01:00
use PHPUnit\Framework\TestCase;
2016-04-07 22:36:02 +02:00
2017-02-03 12:58:25 +01:00
class CsvDatasetTest extends TestCase
2016-04-07 22:36:02 +02:00
{
/**
* @expectedException \Phpml\Exception\FileException
2016-04-07 22:36:02 +02:00
*/
public function testThrowExceptionOnMissingFile()
{
new CsvDataset('missingFile', 3);
}
2016-04-16 21:24:40 +02:00
public function testSampleCsvDatasetWithHeaderRow()
2016-04-07 22:36:02 +02:00
{
$filePath = dirname(__FILE__).'/Resources/dataset.csv';
$dataset = new CsvDataset($filePath, 2, true);
2016-12-12 19:31:30 +01:00
$this->assertCount(10, $dataset->getSamples());
$this->assertCount(10, $dataset->getTargets());
2016-04-07 22:36:02 +02:00
}
2016-04-16 21:24:40 +02:00
public function testSampleCsvDatasetWithoutHeaderRow()
{
$filePath = dirname(__FILE__).'/Resources/dataset.csv';
$dataset = new CsvDataset($filePath, 2, false);
2016-12-12 19:31:30 +01:00
$this->assertCount(11, $dataset->getSamples());
$this->assertCount(11, $dataset->getTargets());
2016-04-16 21:24:40 +02:00
}
2016-04-07 22:36:02 +02:00
}