Use assertCount in tests

This commit is contained in:
Arkadiusz Kondas 2016-12-12 19:31:30 +01:00
parent b6fe290c65
commit a78ebc159a
8 changed files with 25 additions and 25 deletions

View File

@ -15,14 +15,14 @@ class KMeansTest extends \PHPUnit_Framework_TestCase
$kmeans = new KMeans(2);
$clusters = $kmeans->cluster($samples);
$this->assertEquals(2, count($clusters));
$this->assertCount(2, $clusters);
foreach ($samples as $index => $sample) {
if (in_array($sample, $clusters[0]) || in_array($sample, $clusters[1])) {
unset($samples[$index]);
}
}
$this->assertEquals(0, count($samples));
$this->assertCount(0, $samples);
}
public function testKMeansInitializationMethods()
@ -42,11 +42,11 @@ class KMeansTest extends \PHPUnit_Framework_TestCase
$kmeans = new KMeans(4, KMeans::INIT_KMEANS_PLUS_PLUS);
$clusters = $kmeans->cluster($samples);
$this->assertEquals(4, count($clusters));
$this->assertCount(4, $clusters);
$kmeans = new KMeans(4, KMeans::INIT_RANDOM);
$clusters = $kmeans->cluster($samples);
$this->assertEquals(4, count($clusters));
$this->assertCount(4, $clusters);
}
/**

View File

@ -34,13 +34,13 @@ class RandomSplitTest extends \PHPUnit_Framework_TestCase
$randomSplit = new RandomSplit($dataset, 0.5);
$this->assertEquals(2, count($randomSplit->getTestSamples()));
$this->assertEquals(2, count($randomSplit->getTrainSamples()));
$this->assertCount(2, $randomSplit->getTestSamples());
$this->assertCount(2, $randomSplit->getTrainSamples());
$randomSplit2 = new RandomSplit($dataset, 0.25);
$this->assertEquals(1, count($randomSplit2->getTestSamples()));
$this->assertEquals(3, count($randomSplit2->getTrainSamples()));
$this->assertCount(1, $randomSplit2->getTestSamples());
$this->assertCount(3, $randomSplit2->getTrainSamples());
}
public function testDatasetRandomSplitWithSameSeed()

View File

@ -22,8 +22,8 @@ class CsvDatasetTest extends \PHPUnit_Framework_TestCase
$dataset = new CsvDataset($filePath, 2, true);
$this->assertEquals(10, count($dataset->getSamples()));
$this->assertEquals(10, count($dataset->getTargets()));
$this->assertCount(10, $dataset->getSamples());
$this->assertCount(10, $dataset->getTargets());
}
public function testSampleCsvDatasetWithoutHeaderRow()
@ -32,7 +32,7 @@ class CsvDatasetTest extends \PHPUnit_Framework_TestCase
$dataset = new CsvDataset($filePath, 2, false);
$this->assertEquals(11, count($dataset->getSamples()));
$this->assertEquals(11, count($dataset->getTargets()));
$this->assertCount(11, $dataset->getSamples());
$this->assertCount(11, $dataset->getTargets());
}
}

View File

@ -13,10 +13,10 @@ class GlassDatasetTest extends \PHPUnit_Framework_TestCase
$glass = new GlassDataset();
// whole dataset
$this->assertEquals(214, count($glass->getSamples()));
$this->assertEquals(214, count($glass->getTargets()));
$this->assertCount(214, $glass->getSamples());
$this->assertCount(214, $glass->getTargets());
// one sample features count
$this->assertEquals(9, count($glass->getSamples()[0]));
$this->assertCount(9, $glass->getSamples()[0]);
}
}

View File

@ -13,10 +13,10 @@ class IrisDatasetTest extends \PHPUnit_Framework_TestCase
$iris = new IrisDataset();
// whole dataset
$this->assertEquals(150, count($iris->getSamples()));
$this->assertEquals(150, count($iris->getTargets()));
$this->assertCount(150, $iris->getSamples());
$this->assertCount(150, $iris->getTargets());
// one sample features count
$this->assertEquals(4, count($iris->getSamples()[0]));
$this->assertCount(4, $iris->getSamples()[0]);
}
}

View File

@ -13,10 +13,10 @@ class WineDatasetTest extends \PHPUnit_Framework_TestCase
$wine = new WineDataset();
// whole dataset
$this->assertEquals(178, count($wine->getSamples()));
$this->assertEquals(178, count($wine->getTargets()));
$this->assertCount(178, $wine->getSamples());
$this->assertCount(178, $wine->getTargets());
// one sample features count
$this->assertEquals(13, count($wine->getSamples()[0]));
$this->assertCount(13, $wine->getSamples()[0]);
}
}

View File

@ -22,8 +22,8 @@ class FilesDatasetTest extends \PHPUnit_Framework_TestCase
$dataset = new FilesDataset($rootPath);
$this->assertEquals(50, count($dataset->getSamples()));
$this->assertEquals(50, count($dataset->getTargets()));
$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())));

View File

@ -39,7 +39,7 @@ class SetTest extends \PHPUnit_Framework_TestCase
$this->assertInternalType('array', $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()
@ -48,7 +48,7 @@ class SetTest extends \PHPUnit_Framework_TestCase
$this->assertInternalType('array', $cartesian);
$this->assertEquals([new Set(['A', 1]), new Set(['A', 2])], $cartesian);
$this->assertEquals(2, count($cartesian));
$this->assertCount(2, $cartesian);
}
public function testContains()