mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-24 22:07:33 +00:00
39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
|
<?php
|
||
|
|
||
|
declare (strict_types = 1);
|
||
|
|
||
|
namespace tests\Phpml\Dataset;
|
||
|
|
||
|
use Phpml\Dataset\FilesDataset;
|
||
|
|
||
|
class FilesDatasetTest extends \PHPUnit_Framework_TestCase
|
||
|
{
|
||
|
/**
|
||
|
* @expectedException \Phpml\Exception\DatasetException
|
||
|
*/
|
||
|
public function testThrowExceptionOnMissingRootFolder()
|
||
|
{
|
||
|
new FilesDataset('some/not/existed/path');
|
||
|
}
|
||
|
|
||
|
public function testLoadFilesDatasetWithBBCData()
|
||
|
{
|
||
|
$rootPath = dirname(__FILE__).'/Resources/bbc';
|
||
|
|
||
|
$dataset = new FilesDataset($rootPath);
|
||
|
|
||
|
$this->assertEquals(50, count($dataset->getSamples()));
|
||
|
$this->assertEquals(50, count($dataset->getTargets()));
|
||
|
|
||
|
$targets = ['business', 'entertainment', 'politics', 'sport', 'tech'];
|
||
|
$this->assertEquals($targets, array_values(array_unique($dataset->getTargets())));
|
||
|
|
||
|
$firstSample = file_get_contents($rootPath.'/business/001.txt');
|
||
|
$this->assertEquals($firstSample, $dataset->getSamples()[0][0]);
|
||
|
|
||
|
$lastSample = file_get_contents($rootPath.'/tech/010.txt');
|
||
|
$this->assertEquals($lastSample, $dataset->getSamples()[49][0]);
|
||
|
}
|
||
|
|
||
|
}
|