php-ml/tests/Phpml/Dataset/FilesDatasetTest.php
Tomáš Votruba a348111e97 Add PHPStan and level to max (#168)
* tests: update to PHPUnit 6.0 with rector

* fix namespaces on tests

* composer + tests: use standard test namespace naming

* update travis

* resolve conflict

* phpstan lvl 2

* phpstan lvl 3

* phpstan lvl 4

* phpstan lvl 5

* phpstan lvl 6

* phpstan lvl 7

* level max

* resolve conflict

* [cs] clean empty docs

* composer: bump to PHPUnit 6.4

* cleanup

* composer + travis: add phpstan

* phpstan lvl 1

* composer: update dev deps

* phpstan fixes

* update Contributing with new tools

* docs: link fixes, PHP version update

* composer: drop php-cs-fixer, cs already handled by ecs

* ecs: add old set rules

* [cs] apply rest of rules
2018-01-06 13:09:33 +01:00

44 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Phpml\Tests\Dataset;
use Phpml\Dataset\FilesDataset;
use Phpml\Exception\DatasetException;
use PHPUnit\Framework\TestCase;
class FilesDatasetTest extends TestCase
{
public function testThrowExceptionOnMissingRootFolder(): void
{
$this->expectException(DatasetException::class);
new FilesDataset('some/not/existed/path');
}
public function testLoadFilesDatasetWithBBCData(): void
{
$rootPath = dirname(__FILE__).'/Resources/bbc';
$dataset = new FilesDataset($rootPath);
$this->assertCount(50, $dataset->getSamples());
$this->assertCount(50, $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]);
$firstTarget = 'business';
$this->assertEquals($firstTarget, $dataset->getTargets()[0]);
$lastSample = file_get_contents($rootPath.'/tech/010.txt');
$this->assertEquals($lastSample, $dataset->getSamples()[49][0]);
$lastTarget = 'tech';
$this->assertEquals($lastTarget, $dataset->getTargets()[49]);
}
}