mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-11 08:10:56 +00:00
Use assertCount in tests
This commit is contained in:
parent
b6fe290c65
commit
a78ebc159a
@ -15,14 +15,14 @@ class KMeansTest extends \PHPUnit_Framework_TestCase
|
|||||||
$kmeans = new KMeans(2);
|
$kmeans = new KMeans(2);
|
||||||
$clusters = $kmeans->cluster($samples);
|
$clusters = $kmeans->cluster($samples);
|
||||||
|
|
||||||
$this->assertEquals(2, count($clusters));
|
$this->assertCount(2, $clusters);
|
||||||
|
|
||||||
foreach ($samples as $index => $sample) {
|
foreach ($samples as $index => $sample) {
|
||||||
if (in_array($sample, $clusters[0]) || in_array($sample, $clusters[1])) {
|
if (in_array($sample, $clusters[0]) || in_array($sample, $clusters[1])) {
|
||||||
unset($samples[$index]);
|
unset($samples[$index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->assertEquals(0, count($samples));
|
$this->assertCount(0, $samples);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testKMeansInitializationMethods()
|
public function testKMeansInitializationMethods()
|
||||||
@ -42,11 +42,11 @@ class KMeansTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$kmeans = new KMeans(4, KMeans::INIT_KMEANS_PLUS_PLUS);
|
$kmeans = new KMeans(4, KMeans::INIT_KMEANS_PLUS_PLUS);
|
||||||
$clusters = $kmeans->cluster($samples);
|
$clusters = $kmeans->cluster($samples);
|
||||||
$this->assertEquals(4, count($clusters));
|
$this->assertCount(4, $clusters);
|
||||||
|
|
||||||
$kmeans = new KMeans(4, KMeans::INIT_RANDOM);
|
$kmeans = new KMeans(4, KMeans::INIT_RANDOM);
|
||||||
$clusters = $kmeans->cluster($samples);
|
$clusters = $kmeans->cluster($samples);
|
||||||
$this->assertEquals(4, count($clusters));
|
$this->assertCount(4, $clusters);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,13 +34,13 @@ class RandomSplitTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$randomSplit = new RandomSplit($dataset, 0.5);
|
$randomSplit = new RandomSplit($dataset, 0.5);
|
||||||
|
|
||||||
$this->assertEquals(2, count($randomSplit->getTestSamples()));
|
$this->assertCount(2, $randomSplit->getTestSamples());
|
||||||
$this->assertEquals(2, count($randomSplit->getTrainSamples()));
|
$this->assertCount(2, $randomSplit->getTrainSamples());
|
||||||
|
|
||||||
$randomSplit2 = new RandomSplit($dataset, 0.25);
|
$randomSplit2 = new RandomSplit($dataset, 0.25);
|
||||||
|
|
||||||
$this->assertEquals(1, count($randomSplit2->getTestSamples()));
|
$this->assertCount(1, $randomSplit2->getTestSamples());
|
||||||
$this->assertEquals(3, count($randomSplit2->getTrainSamples()));
|
$this->assertCount(3, $randomSplit2->getTrainSamples());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDatasetRandomSplitWithSameSeed()
|
public function testDatasetRandomSplitWithSameSeed()
|
||||||
|
@ -22,8 +22,8 @@ class CsvDatasetTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$dataset = new CsvDataset($filePath, 2, true);
|
$dataset = new CsvDataset($filePath, 2, true);
|
||||||
|
|
||||||
$this->assertEquals(10, count($dataset->getSamples()));
|
$this->assertCount(10, $dataset->getSamples());
|
||||||
$this->assertEquals(10, count($dataset->getTargets()));
|
$this->assertCount(10, $dataset->getTargets());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSampleCsvDatasetWithoutHeaderRow()
|
public function testSampleCsvDatasetWithoutHeaderRow()
|
||||||
@ -32,7 +32,7 @@ class CsvDatasetTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$dataset = new CsvDataset($filePath, 2, false);
|
$dataset = new CsvDataset($filePath, 2, false);
|
||||||
|
|
||||||
$this->assertEquals(11, count($dataset->getSamples()));
|
$this->assertCount(11, $dataset->getSamples());
|
||||||
$this->assertEquals(11, count($dataset->getTargets()));
|
$this->assertCount(11, $dataset->getTargets());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,10 @@ class GlassDatasetTest extends \PHPUnit_Framework_TestCase
|
|||||||
$glass = new GlassDataset();
|
$glass = new GlassDataset();
|
||||||
|
|
||||||
// whole dataset
|
// whole dataset
|
||||||
$this->assertEquals(214, count($glass->getSamples()));
|
$this->assertCount(214, $glass->getSamples());
|
||||||
$this->assertEquals(214, count($glass->getTargets()));
|
$this->assertCount(214, $glass->getTargets());
|
||||||
|
|
||||||
// one sample features count
|
// one sample features count
|
||||||
$this->assertEquals(9, count($glass->getSamples()[0]));
|
$this->assertCount(9, $glass->getSamples()[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,10 @@ class IrisDatasetTest extends \PHPUnit_Framework_TestCase
|
|||||||
$iris = new IrisDataset();
|
$iris = new IrisDataset();
|
||||||
|
|
||||||
// whole dataset
|
// whole dataset
|
||||||
$this->assertEquals(150, count($iris->getSamples()));
|
$this->assertCount(150, $iris->getSamples());
|
||||||
$this->assertEquals(150, count($iris->getTargets()));
|
$this->assertCount(150, $iris->getTargets());
|
||||||
|
|
||||||
// one sample features count
|
// one sample features count
|
||||||
$this->assertEquals(4, count($iris->getSamples()[0]));
|
$this->assertCount(4, $iris->getSamples()[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,10 @@ class WineDatasetTest extends \PHPUnit_Framework_TestCase
|
|||||||
$wine = new WineDataset();
|
$wine = new WineDataset();
|
||||||
|
|
||||||
// whole dataset
|
// whole dataset
|
||||||
$this->assertEquals(178, count($wine->getSamples()));
|
$this->assertCount(178, $wine->getSamples());
|
||||||
$this->assertEquals(178, count($wine->getTargets()));
|
$this->assertCount(178, $wine->getTargets());
|
||||||
|
|
||||||
// one sample features count
|
// one sample features count
|
||||||
$this->assertEquals(13, count($wine->getSamples()[0]));
|
$this->assertCount(13, $wine->getSamples()[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ class FilesDatasetTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$dataset = new FilesDataset($rootPath);
|
$dataset = new FilesDataset($rootPath);
|
||||||
|
|
||||||
$this->assertEquals(50, count($dataset->getSamples()));
|
$this->assertCount(50, $dataset->getSamples());
|
||||||
$this->assertEquals(50, count($dataset->getTargets()));
|
$this->assertCount(50, $dataset->getTargets());
|
||||||
|
|
||||||
$targets = ['business', 'entertainment', 'politics', 'sport', 'tech'];
|
$targets = ['business', 'entertainment', 'politics', 'sport', 'tech'];
|
||||||
$this->assertEquals($targets, array_values(array_unique($dataset->getTargets())));
|
$this->assertEquals($targets, array_values(array_unique($dataset->getTargets())));
|
||||||
|
@ -39,7 +39,7 @@ class SetTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertInternalType('array', $power);
|
$this->assertInternalType('array', $power);
|
||||||
$this->assertEquals([new Set(), new Set(['A']), new Set(['B']), new Set(['A', 'B'])], $power);
|
$this->assertEquals([new Set(), new Set(['A']), new Set(['B']), new Set(['A', 'B'])], $power);
|
||||||
$this->assertEquals(4, count($power));
|
$this->assertCount(4, $power);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCartesian()
|
public function testCartesian()
|
||||||
@ -48,7 +48,7 @@ class SetTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertInternalType('array', $cartesian);
|
$this->assertInternalType('array', $cartesian);
|
||||||
$this->assertEquals([new Set(['A', 1]), new Set(['A', 2])], $cartesian);
|
$this->assertEquals([new Set(['A', 1]), new Set(['A', 2])], $cartesian);
|
||||||
$this->assertEquals(2, count($cartesian));
|
$this->assertCount(2, $cartesian);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testContains()
|
public function testContains()
|
||||||
|
Loading…
Reference in New Issue
Block a user