mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-22 04:55:10 +00:00
add tests for datasets
This commit is contained in:
parent
9c18a5a22d
commit
db9d57cd22
29
tests/Phpml/Dataset/ArrayDatasetTest.php
Normal file
29
tests/Phpml/Dataset/ArrayDatasetTest.php
Normal 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());
|
||||
}
|
||||
}
|
28
tests/Phpml/Dataset/CsvDatasetTest.php
Normal file
28
tests/Phpml/Dataset/CsvDatasetTest.php
Normal 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()));
|
||||
}
|
||||
}
|
11
tests/Phpml/Dataset/Resources/dataset.csv
Normal file
11
tests/Phpml/Dataset/Resources/dataset.csv
Normal 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
|
|
Loading…
Reference in New Issue
Block a user