add tests for datasets

This commit is contained in:
Arkadiusz Kondas 2016-04-07 22:36:02 +02:00
parent 9c18a5a22d
commit db9d57cd22
3 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,29 @@
<?php
declare (strict_types = 1);
namespace tests\Phpml\Dataset;
use Phpml\Dataset\ArrayDataset;
class ArrayDatasetTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \Phpml\Exception\InvalidArgumentException
*/
public function testThrowExceptionOnInvalidArgumentsSize()
{
new ArrayDataset([0, 1], [0]);
}
public function testArrayDataset()
{
$dataset = new ArrayDataset(
$samples = [[1], [2], [3], [4]],
$labels = ['a', 'a', 'b', 'b']
);
$this->assertEquals($samples, $dataset->getSamples());
$this->assertEquals($labels, $dataset->getLabels());
}
}

View File

@ -0,0 +1,28 @@
<?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);
}
public function testSampleCsvDataset()
{
$filePath = dirname(__FILE__).'/Resources/dataset.csv';
$dataset = new CsvDataset($filePath, 2, true);
$this->assertEquals(10, count($dataset->getSamples()));
$this->assertEquals(10, count($dataset->getLabels()));
}
}

View File

@ -0,0 +1,11 @@
feature1,feature2,label
1,1,a
2,1,b
3,1,c
4,5,a
2,4,a
1,5,a
2,6,b
3,7,c
4,4,a
2,0,a
1 feature1 feature2 label
2 1 1 a
3 2 1 b
4 3 1 c
5 4 5 a
6 2 4 a
7 1 5 a
8 2 6 b
9 3 7 c
10 4 4 a
11 2 0 a