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

45 lines
1.3 KiB
PHP
Raw Normal View History

2016-07-16 21:29:40 +00:00
<?php
2016-11-20 21:53:17 +00:00
declare(strict_types=1);
2016-07-16 21:29:40 +00:00
namespace tests\Phpml\Dataset;
use Phpml\Dataset\FilesDataset;
2017-02-03 11:58:25 +00:00
use PHPUnit\Framework\TestCase;
2016-07-16 21:29:40 +00:00
2017-02-03 11:58:25 +00:00
class FilesDatasetTest extends TestCase
2016-07-16 21:29:40 +00:00
{
/**
* @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);
2016-12-12 18:31:30 +00:00
$this->assertCount(50, $dataset->getSamples());
$this->assertCount(50, $dataset->getTargets());
2016-07-16 21:29:40 +00:00
$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]);
$firstTarget = 'business';
$this->assertEquals($firstTarget, $dataset->getTargets()[0]);
2016-07-16 21:29:40 +00:00
$lastSample = file_get_contents($rootPath.'/tech/010.txt');
$this->assertEquals($lastSample, $dataset->getSamples()[49][0]);
$lastTarget = 'tech';
$this->assertEquals($lastTarget, $dataset->getTargets()[49]);
2016-07-16 21:29:40 +00:00
}
}